python-05 conditions, loops and other statements

Condition #, circulation and other statements 
# 5.1 talk and print Import
# 5.1.1 plurality of print parameters
# print ( 'Age:', 42 is)
#
# name = 'Gumby'
# = Salutation 'is Mr.'
# = Greeting ' hello '
# Print (Greeting, Salutation, name)
# Print ( "the I", "Wish", "to", "Register", "A", "Complaint", On Sep = "_")
# end TAIL seq partition symbol
# 5.1.2 rename introduced
# # import Math. 1,
# import from Math *
# import from Math Tan
# import from Math Tan, SiN

# rename
# import Math foobar AS
# Print (foobar.sqrt (. 4))
#
# Import from Math sqrt foo AS
# Print (foo (. 4))

# 5.2 assignment magic
# 5.2.1 unpacking sequence
# x, y,z = 1, 2, 3
# print (x, y)

# With an asterisk to collect excess value data result tuples
# A, B, * REST = [. 1, 2,. 3,. 4]
# Print (REST)
# A, * REST, B = [. 1, 2, . 3,. 4]
# Print (REST)
# Print (B)

# chain 5.2.2 assignment
# X = Y = [. 1, 2,. 3]
# Print (X Y IS)
# B = [. 1, 2,. 3]
a = # [. 1, 2,. 3]
# Print (a iS B)

# = + 5.2.3 reinforcing assignment - = * =

# 5.3 code block: indentation fun

# 5.4 and Conditional statements

# n this 5.4.1 is a useless boolean
# None 0 false false '' () [] {}
# truth values: in addition to a false value

# Print (true)
# Print (BOOL (. 1))

# 5.4.2 conditional implementation and if the statement
"" "
name = the INPUT ( '? the What IS your name')
if name.endswith ( 'Gumby'):
Print ( 'the Hello, Mr.Gumby')
" ""
# the else clause 5.4.3

INPUT name = # ( 'your name ?: What IS')
# Status = "Friend" IF name.endswith ( "Gumby") the else "Stranger"
# name.endswith IF ( 'Gumby'):
# Print ( 'the Hello, Mr.Gumby ')
# the else:
# Print (' the Hello, Stranger ')
# Print (Status)

# elif clause 5.4.4 else if Abbreviation

# 5.4.5 nested block

# 5.4.6 more complex conditions

# 1 , comparison operators! = (<>) Is not <> is equal to the same ==
# Print (. 1! = 2)

# 2. or Boolean operator and

# assertion 5.4.7

# 5.5 cycle
# 5.5.1 while loop
#. 1 = X
# X the while <= 100:
# Print (X)
# =. 1 + X

# 5.5.2 for cycle
# words = [ 'this', 'is', 'an', 'ex', 'parrot'



For in Range Number # (101):
# Print (Number)

# 5.5.3 Iterative dictionary
# D = { 'X':. 1, 'Y': 2, 'Z':}. 3
# for Key in D:
# Print (Key, 'Corresponds to', D [Key])

# 5.5..4 some iterations tools
# 1. parallel iterative
# names = [ 'Anne', 'Beth', 'George', 'Damon']
# = AGEs [ 12 is, 45, 32, 102]
# for I in Range (len (names)):
# Print (names [I], 'IS', AGEs [I], 'years Old')
# Print ( '{} IS { years old'.format} (names [I], AGEs [I]))
# Print (List (ZIP (names, AGEs))) # ZIP integration of the two sequences

# print ( '11'.join (reversed ( ' Hello , world! ')))
# 2 Gets the index enumerate iteration
# 3 reverse iteration after iteration and sort sorted (sort), reversed (inclusive swaps) are returned a list of

# 5.5.5 out of the loop
# 1 break ending cycle
# 2 continue end of the iteration
True the while. 3 # / BREAK
# the while True:
# = Word INPUT ( 'Please Enter A Word:')
# Not Word IF:
# BREAK
# Print ( 'This WAS Word', Word)

# 5.5.6 cycle sub else after completion of sentence cycle will be performed else statements

# simple derivation 5.6
# Print ([X * X for X in Range (10)])
#
# Girls = [ 'Alice', 'Bernice', 'Clarice']
# Boys = [ 'Chris', 'Arnold', 'Bob']
# letterGirls} = {
# for Girls Girl in:
. # letterGirls.setdefault (Girl [0], []) the append (Girl)
# Print (letterGirls)
# Print ([B + '+' + G for B in Boys for G in letterGirls [B [0]]])
# [] list
# () generator
# dictionary deduced

# 5.7 threesome Pass del Exec (the eval)
# 5.7.1 pass for doing nothing
# 5.7.2 del delete
# exec and eval 5.7.3 using calculation results and performs string
# exec string code execution
from Math Import sqrt
scope = {}
exec ( '= sqrt. 9', scope)
Print (scope [ ' sqrt '])
Print (scope.keys ())
Print (sqrt (. 4))

# 2.eval Python expression with the string representation of the operator, and returns the result



' ''
X YX equal == Y
X <YX less than y
x> YX is greater than y
x> = YX is greater than or equal to y
x <= YX less than or equal to y
x! = YX is not equal to y
x iS YX and y are the same object
x is not yx and y are different objects
x in yx is a container (e.g., sequence) the member y
x not in yx not a container (e.g., sequence) the member y

chr (n) returns a string containing only one character, the character corresponding to the incoming order value n ( ≤n 0 <256)
the eval (Source [, Globals [, about locals]]) calculated expression string representation and returns the result of
exec (source [, globals [,about locals]]) will be executed as the statement string
enumerate (seq) generates the iteration index value 
ord (c) receiving a string containing only one character, and the character value of this return order (an integer)
Range ([Start,] STOP [, STEP]) to create a list of integers of
the reversed (seq) returns the value of seq reverse order, so as to iterate
sorted (seq [, cmp] [ , key] [, reverse]) returns a list containing all of seq values and these values are sorted
xrange ([start,] stop [ , step]) to create an object for iteration xrange
zip (seq1, seq2, ...) creates a new sequence suitable for parallel iterative
' '


Guess you like

Origin www.cnblogs.com/fuyouqiang/p/11844626.html