1.Python helloworld!
#!/usr/bin/env python
print "Hello World!!!"
2.Python Basic variable naming
Legal variables:
Name= ' Freeman '
Nameinfo = ' Freeman '
Illegal variable:
Name-info = ' Freeman '
@name = ' Freeman '
Summary: Variables cannot be named with special characters and operators as variables, and you can use the wrong division method for named variables such as Nameinfo
3.Python Judgment Statement
#!/usr/bin/env python
Print "Hello1"
If 1 > 10:
Print "Hello2"
If 2 = = 4:
Print "Hello3"
Print "Hello 4"
Grammar:
An If expression:
Code logic block
Elif expression:
Code logic block
Else
Code logic block
Summary: Because Python does not have a program close character, it is because it uses code indentation to express a piece of code or logic
3.Python Arithmetic expressions
= = equals
>= greater than or equal to
<= less than or equal to
4.Python Loop statement
#!/usr/bin/env python
While True:
Print "HH"
Target=false
While True:
Print "GG"
Target=true
Break
If Target:
Break
#!/usr/bin/env python
Import Random
Import tab
Suiji=random.randrange (4)
#num =raw_input (' Please number: ')
While True:
Num=raw_input (' Please number: ')
if int (num) = = Suiji:
print "OK"
Print Suiji
Break
Elif num > Suiji:
Print "Xiao Xiao Xiao"
Print Suiji
Continue
Elif Num < Suiji:
Print "Dadada"
Print Suiji
Continue
5.Python Basic data types
Several data types built into Python are: lists, tuples, dictionaries, strings, numbers, character points, etc.
6.Python Several modes of open file
R Read mode
W Write mode
A append mode
A + w+ r+
7.Python syntax sugar (IF true and ternary operator)
def is_freeman (name):
res = True if name.lower () = = "Freeman" Else False
return res
Print Is_freeman ("Freeman")
Print Is_freeman ("free")
#lambda
A = lambda x, y:x > Y
Print a (5,3)
8.Python use the above methods to practice
#!/usr/bin/env python
User=raw_input ("Please Name:")
For I in range (3):
Passwd=raw_input ("Please passwd:")
if user = = ' JZCLVN ' and passwd = = ' Redhat ':
Print "Wlecome"
Break
Else
print "Bye"
Else
Print "Lock User"
Python Foundation One