Python Learning Sharing-basics

Source: Internet
Author: User

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

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.