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)