Python Learning notes (i)

Source: Internet
Author: User
Tags logical operators

1. Features

(1) do not use semicolons as the end of the statement, end without any symbols. Therefore, each line can only write one statement.

(2) do not use curly braces as a range callout for control statements such as branching, looping, etc., and are only labeled with tabs and spaces.

2. Output function:print

(Note: after the 3.0 version, the output must be enclosed in parentheses.)

Print 2

Print 3+4

print ' Hello world! '

Print "Hello world!"

Print ("Hello world!")

print ' My name is ', T # t=xiaoming

3. Input function

Input ()

a=input () # Note When typing from the keyboard, you will get an error if the character needs to be enclosed in quotation marks .

a=raw_input () # input characters do not need to be enclosed in quotation marks.

4. Variable definition

variables in Python do not need to define the type first, because there is a coercion type conversion, a variable can be any type of data, just when you want to use a name, and then directly assign the value. and can be given arbitrary data types during use.

A=1

B=false

C= ' Goodbye '

A=c

5. Naming rules for variables.

(1) must be preceded by letters or underscores

(2) the remainder can be letters, numbers, underscores (_)

(3) Case sensitive

6. Logical operators

and--and

or--or

not--Non -

A=false

B=not a # b= True

7. Conditional Control Statement if

If a>b:

Print a

Elif A<b:

Print B

Else

Print 0

8. Loop statement while(no switch... Case statement)

While A!=0

Print a

A=input ()

Print "Over"

9 . Usage of Circular statement for

for I in range (1,101) # i take each integer from 1 to + , excluding 101

Print I

The method of introducing the module.

From module name Import method name

From random import Randint

A=randint (1,100) # After the parentheses must indicate the range of values, or error

Python Learning notes (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.