The cycle of Python basics

Source: Internet
Author: User

1.1 Variable Command

NUMS_OF_GF = 19

NUMSOFALEXGF = 19

No, NAME-OF-ALEX-GF =19.

The middle cannot have a minus sign, a space

Numbers, special characters do not start

Keyword cannot define a variable

Can only start with a letter and an underscore

 

1.2 Input

python3.x input ()

python2.x Raw_input ()

python2.x input () > input what format to output what format

Name = input ("Please input your name")

Print ("Your name is%s"% name)

If the input is a numeric type and you also want to manipulate the numbers, it is best to cast with INI

Raw_input output is a string format that needs to be converted into a numeric type

input_num = Int (raw_inout ("Please input your num:"))


Name =Raw_input ("Name:"). Strip ()##Remove the space between the front and back, do not remove theRoomSpace, but you can also specify what to go for,Just go back and forth.
Age =Raw_input ("Age:")
Job =Raw_input ("Job:")
Print ("Info1 of []:" + name +"\ nname:[] "+ name +"\ nAge:[] "+ Age +"\ nJob:[] "+ job)
Print ("Info2 of%s:\ nname:%s\age:%s\job:%s "% (name,name,age,job))
# # Paragraph
msg = "'
Info3 of%s:
name:%s
age:%s
job:%s
"% (Name,name,age,job)
Print (msg)

1.3 If ... else

Loop 3 times to guess numbers

While multiple nesting, you can use tag as a variable to judge

Tag = True

While tag:

......

......

Tag =false

Countinue

Luck_num =6
Time =0
num =None
While luck_num! = num:
num =intRaw_input ("Please input your num:"))
If Luck_num > num:
print ( "your num is less than ")
elif luck_num < num:
print (" Your num is more than ")
Time + = 1
if time > 3:
print (" Your guess time more than 3 time ")
break
Span style= "color: #000080; Font-weight:bold ">else:
print (" OK ")

Luck_num =6
Time =0
num =None
While luck_num! = numand Time <3:
num =intRaw_input ("Please input your num:"))
If Luck_num > num:
Print ("Your num is less than")
Elif Luck_num < num:
Print ("Your num is more than")
Time + = 1
# If time > 3:
# print ("Your guess time more than 3 time")
# break
Else
if luck_num = = num:
print ("OK")
Else:
print ("Too Much Retrys")

   

Luck_num =6
Time =0
num =None
While luck_num! = numand Time <3:
num =intRaw_input ("Please input your num:"))
If Luck_num > num:
Print ("Your num is less than")
Elif Luck_num < num:
Print ("Your num is more than")
Time + = 1
# If time > 3:
# print ("Your guess time more than 3 time")
# break

if luck_num = = num: # # can be re-judged outside the while
print ("OK")
Else
print ("Too Much Retrys")


Luck_num =6
Time =0
num =None
While time <3:
num =intRaw_input ("Please input your num:"))
If Luck_num > num:
Print ("Your num is less than")
Elif Luck_num < num:
Print ("Your num is more than")
Else:
print ("OK")
Break
Time + = 1
# If time > 3:
# print ("Your guess time more than 3 time")
# break
Else
print ("Too Much Retrys")

Range (10):
Print I

0
1
2
3
4
5
6
7
8
9

##ManyLayerFollowRing
For JInchRange5):
For IInchRange10):
If i<5:
Continue# I <5Just jump out of this timeRing
# print (i) # # 5, 6, 7, 8, 9
# If I > 8:
# break
# print (i) # # 5, 6, 7 8
If j>3:
Break#Jump out of thisLayerThe loop
Print (i) # #5,6,,7,8

The cycle of Python 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.