Assign Value Printing
name = "Hello, world"
msg = "I ' m Alex Li"
Print (name)
Print (msg)
#单行注释
"""
Multi-line comments
"""
---------------------------------------------------------------------
Three modes of output:
One:
Splicing method, not recommended, each time to open up new memory
Two:
Info2 = "'
----info of {_name}----
Name:{_name}
Age:{_age}
Job:{_job}
Salary:{_salary}
". Format (_name = name,
_age = age,
_job = Job,
_salary = salary)
Print (Info2)
Three:
Info3 = "'
----info of {0}----
NAME:{0}
Age:{1}
JOB:{2}
SALARY:{3}
". Format (name, age, job, salary)
Print (INFO3)
---------------------------------------------------------------------
Condition Judgment:
Import Getpass
#密文导入框架 (terminal display)
#存密码
_username = ' Zhou '
_password = ' abc123 '
Username = input ("Username:")
#password = Getpass.getpass ("Password:")
Password = input ("Password:")
#if Else logic
#else强制缩进
If _username = = Username and _password = = password:
#if的子代码
Print ("Welcome to user {name} python". Format (Name=username))
Else
#else的子代码
Print ("Invalid username or password!")
Print ("My Tina")
---------------------------------------------------------------------
While loop:
Count = 0
While True:
Print ("Count:", count)
Count = count + 1 #count + = 1
if Count = = 10:
Break
---------------------------------------------------------------------
Three input exercises:
Age_of_oldboy = 56;
Count = 0
While Count < 3:
guess_age = Int (input ("Guess Age:"))
if guess_age = = Age_of_oldboy:
Print ("Yes,you got It")
Elif guess_age > Age_of_oldboy:
Print ("Think smaller ...")
Else
Print ("Think bigger ...")
Count + = 1
Print ("Count:", count)
Else
Print ("Sorry, you have used up the number of times")
---------------------------------------------------------------------
For loop Printing:
#循环10次 range equals the set of variables, a set of data 0-9
#打印0, 2,4,6,8 0,10,2
#打印1, 3,5,7,9 1,10,2
For I in range (0, 10, 3):
Print ("Loop", i)
For I in range (10):
Print ("Loop", i)
Nesting of For loops:
For I in range (4):
Print ("-------", i)
For j in Range (4):
Print (j)
If J > 1:
Break
---------------------------------------------------------------------
Python Transcript first week