python3.5 the first chapter of learning

Source: Internet
Author: User

In Python, variable assignments or other statements do not need to be added ";"

In Python, indentation is especially important!

Conditional statement and Loop statement, add ":"

One, variable assignment

Name = "Cecelia"
name2 = Name
Print ("My name is", name,name2)

Second, the use of annotation symbols

1. Use #, #与注释内容之间要有空格

# first Trying

2. Use "' or " "

‘‘‘
For I in Range (0,10,2):
If i<3:
Print ("Loop", i)
Else
Continue
Print ("Hhe")
‘‘‘

"' can also be used to assign multiple rows of content to a variable in addition to annotations
Msg= ""
Gf_of_oldboy = "Chen Rong Hua"

Print ("Hello,", Gf_of_oldboy)
‘‘‘
Print (msg)


Third, user input (use of input)
Name = input ("name")
Age = Input ("Age")

2. Ciphertext effect
Import Getpass
Username = input ("Username:")

Password = getpass.getpass ("password")

# to run the results under CMD
3. Connect the value of the input variable in the output
3.1%s or%d
msg = "'---Information of%s---
name:%s
age:%d
job:%s
'% (name, name, int (age), job)

Print (msg)
3.2. Format (), {variable name}
Info2 = "'---information2 of {_name}---
Name:{_name}
Age:{_age}
Job:{job}
". Format (_name=name,
_age=age,
Job=job)

Print (Info2)
3.3. Format (), {input Ordinal}
Info3 = "'---Information3 of {0}---
NAME:{0}
Age:{1}
JOB:{2}
". Format (name, age, Job)

Print (INFO3)

Iv.. If ... (Elif ...) else ... Conditional statement (note that theif statement should be added after:)
4.1
If _username = = Username and Password = = _passwd:
Print ("Welcome user {Name} login ...". Format (Name=username))
Else
Print ("Invalid username or password")

4.2
if age = = Age_of_oldboy:
Print ("Yes,you got it.")
Elif Age>age_of_oldboy:
Print ("Think smaller")
Else
Print ("Think older")

V. Circular statements
5.1 While loop (plus after statement:)
Count = 0

While Count <3:
age = Int (input ("Guess Age:"))
if age = = Age_of_oldboy:
Print ("Yes,you got it.")
Break
Elif Age>age_of_oldboy:
Print ("Think smaller")
Else
Print ("Think older")
Count=count+1
Else
Print ("Tried so many times")
5.2 For Loop (forstatement after:)
For I in Range (0,10,2):
If i<3:
Print ("Loop", i)
Else
Continue
Print ("Hhe")
For statement, in range (ARG1,ARG2,ARG3)
Arg1: initial value (including)
ARG2: Final value (not included)
Arg3: Step Size





python3.5 the first chapter of learning

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.