Article From:https://www.cnblogs.com/songzijian/p/8954753.html

1.python” features: beautiful, clear and simple.

2.python2″ and “python3”:

> 2. default encoding mode ASCII

(showing Chinese: the first line: encoding:utf-8″ * * * *).

> (for example: Print (“content”) or print “content”)

>: raw_input ().

xrange represents Iterable objects.

> 2. default encoding UTF-8 [string encoding: Unicode].

> 4. can be directly input to input ().

> 6.nonlocal: change non local variables?

3.python classification

> advantages: high efficiency.

> C represents the language: the language

> advantages: the development efficiency is high, the third party library can be cross platform.

> representing language: Python

4. variable

> rule set of variables:

2. can’t be the beginning of numbers.

> [‘and’,’as’,’assert’,’break’,’class’,’continue’,’def’,’del’,’eliF’,’else’,’except’,’exec’,’finally’,’for’,’from’,’global’,’if’,’import’,’in’,’import’,A’,’not’,’or’,’pass’,’print’,’raise’,’return’,’try’,’while’,’with’,’yield’]

5. can’t be too long.

for example:  age_of_oldboy [old boy age] = 56″ old boy 56 years old

number_of_students [number of students] = 80

 

5. constant

> the default is always constant in uppercase (for example, A=3, A is constant).

6. annotation

single line annotation:

.” (can be replaced)

print('ncjieum')
s = '''
djlgiuewn
'''
print(s)

ncjieum

djlgiuewn

###Judge what type of the object is type ()

s = 852
print(s,type(s))

852 <class 'int'>

 

7. basic data type

str (string type): in Python, strings are quoted by quotation marks.

> Print (content + content) can be seamlessly spliced with a plus sign, and a space will appear with comma.

s1=’hello”, s2=’ s2='”China” print (s1+s2) = = “hello China”

 

” msg= “will become annotations, not to go is to change lines.

 bool (Boolean value True)really False  false

> use Boolean values here.

>>> a=3
>>> b=5
>>> 
>>> a > b #Unfounded is False, that is, false
False
>>> 
>>> a < b #The establishment is True, that is, true
True

View Code

 

8. process control if

results
> name = input (‘please enter your name:’).
Print (‘old iron no trouble ‘).
Print (‘cure by disease’)
> num = int (input (please enter your choice))
> Print (“I’ll invite you for lunch”).
> Print (“dinner I invite”).
Print (‘evening health care ‘)
> name = int (input (please enter your choice))
> Print (“I’ll invite you for lunch”).
> Print (“dinner I invite”).
Print (“big health walk up”).
else:
> 5 nested: if added if
> If num = = 5:
> if num2 = = 2:
> else:

the phenomenon of indentation in the code, which is a major feature of python, is forced to be indented to let the program know which condition is dependent on each section of the code.

 

age = int(input('Please enter the age you think'))
if age > 24:
    print('The age has been guessed')
elif age < 24:
    print('The grooves, I'm not so small')
else:
    print('Congratulations on your guessing')

> A 90-100

> C 60-79

> E 0-39

    

9. flow control” while cycle

format: while conditions:

2. loop terminating statement

1)break :(Conditions for direct end cycle) in vitro are still being implemented. 

2)continue : Similar to break, the difference is that it only terminates the cycle, then performs the subsequent loop, and break terminates completely.(The end of the cycle, the next cycle) the condition of the circulation outside is not executed.

  2.while。。。else While cycleWhen break is broken, the else program is not taken

i = 0
while i < 5:
    i += 1
    print('Loop',i)
                                   #Not broken by breakelse:
    print('Finish the program')
print('*******')

ResultsLoop1
Loop 2
Loop 3
Loop 4
Loop 5
Finish the program*******
i = 0
while i < 5:
    i += 1
    print('Loop',i) 
    break                        #It was broken by break
else:
    print('Finish the program')
print('*******')

ResultsLoop1                          #breakJump out of the loop directly and do not execute the else program
*******

 

 

 

Similar Posts:

Link of this Article: The first acquaintance of Python