Python Transcript first week

Source: Internet
Author: User

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

Related Article

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.