1. Python hands-on
Write the first code, print ' Hello World '
Print ('helloWorld')
2. Variables
Variables are intended to store information, are called in the program, identify data names or types.
Rules for variable definitions:
Variable names can only be any combination of letters, numbers, or underscores
The first character of a variable name cannot be a number
Keyword cannot be life as a variable
For easy reading, variable naming generally follows the meaning of the variable itself, such as name, age, and so on.
Name ="Laay" #string-type string Age= + #inttypeProvince="Shandong"NAMEOFTWINSGF="Hanmeimei"NAME_OF_TWINS_GF="Hanmeimei"Address="Shanghai" Address1=addressaddress= "Beijing"#Address1 is assigned a value, not a variable, so it does not change .
3 Notes
# one-line comment, up to 80 characters
"' Multiple lines of comment
4 formatting strings
name= Input ("input your name:") Age=int (Input ("input your Age:")) Job= Input ("input Your job:")Print("name is:", name)Print("Age is :", age)Print("job is:", Job) msg=" "Infomation of user%s:-----------------------------name:%sage:%d job:%s-----------------------------" "%(name,name,age,job)Print(msg)
5 If Else condition
_username =' Laay ' _password=' laay ' username= Input ('input your name:') Password= Input ('Input your password:')if_username = = Username and_password = =Password:Print('login..')Else: Print('username or password is correct ...') Age= 22Guess_num= Int (Input ('input your num:'))ifGuess_num = =Age :Print('congratulations! you got it.')elifGuess_num >Age :Print('Think smaller!')Else: Print('Think bigger!')
6 while Loop
Age = 22counter=0 forIinchRange (10) ifCounter<3: Guess_num= Int (Input ('input your num:')) ifGuess_num = =Age :Print('congratulations! you got it.') Break elifGuess_num >Age :Print('Think smaller!') Else: Print('Think bigger!') Else: Continue_confirm= Input ('Do your want to contnue because is stupid:') ifCountinue_confirm = ='y'counter=0 ciontinueElse: Print('Bye') BreakCount+ = 1
Python Learning Sharing-basics