hello python week one


python comments pytho good programmer does not have to pursue short code, code readability is crucial

to interact with users
convert input input will enter the contents into a string
output print
formatted output% d% s account % d placeholder only integer, representing first come first unlabeled
python basic data types
int integer
float float
str string
list listing
dict dictionary
bool Boolean
operators
basic operators + - * / =
logical operators = =! IS =

Python comments in
what is NOTE: code explanation or comment, the comment only posters, Python is not recognized

annotation classification:
1. single-line comment #

2. Three marks (which may be single or may be three three pairs) '' '
multi-line comment

' ''

"" "
multi-line comment
" ""

input
1.python3 the input
keyword: input ()
python3 the input acquired user input saved as a unified whole string type

input 2.python2 in
1.input ()
you need to tell people what you typed input data type

>>> name = INPUT ( 'INPUT >>> Please:')
Please >>> INPUT: Jason
Traceback (MOST Recent Last Call):
File "<stdin>", Line. 1, in <Module1>
File "<String > ", Line. 1, in <Module1>
NameError: name 'Jason' IS Not defined
>>> name = INPUT ( 'INPUT >>> Please:')
Please >>> INPUT: 'Egon'
>>> name
'egon'
>>> type(name)
<type 'STR'>
>>> name = INPUT ( 'INPUT >>> Please:')
Please >>> INPUT: [1,2,3,4]
>>> name
[. 1, 2,. 3,. 4]
type >>> (name)
<type 'List'>

2.raw_input ()
data entered by the user will raw_input python2 unified also stored as a string
>>> name1 = raw_input ( '>>>>>>> >>>>>>>>>>>: ')
>>>>>>>>>>>>>>>>>>: Jason
>>> NAME1
' Jason '
>>>type(name1)
<type 'str'>
>>> name1 = raw_input('>>>>>>>>>>>>>>>>>>:')
>>>>>>>>>>>>>>>>>>:[1,2,3,4,5]
NAME1 >>>
'[1,2,3,4,5]'
>>> type (NAME1)
<type 'STR'>

: The User input is uniform string


of code changes once, you must be repeated below changes py file
otherwise, or you do not change the code before the program execution (******)

formatted output

    ```python
    name=input('please input your username:')
    age=input('please input your age:')
    print('my name is',name,'my age is',age)
    print('my name is %s,my age is %s' %(name,age))
    
    '''
    my name is 输入的用户名,my age is 输入的年龄
    '''
    
    print('my name is %s my age is %s' %(18,'egon'))
    
    
    Print ( ' My name IS% S My Age IS% D ' % ( ' Egon ' , 18 is ))
     Print ( ' My name IS% S My Age IS% S ' % ( ' Egon ' , 18 is ))
     Print ( ' My Age% S iS My name iS S% ' % ( ' Egon ' , [l, 2,3])) # % S may receive any type of value 
    Print ( ' My name My Age iS iS S% D% ' % ( ' Egon ' , ' XXX ')) # % D can receive a digital type
    

 




Data Types
What is Data: Measuring / recording state of things / features
What is type: different data should have different types of storage
such as: text, video, audio. . .


int int 1,5,56,9165
a float floating-1.1,, 5.0
STR string 'of all content' used for storing annotation information
data type list list ordered list of index [0] as the first data beginning
students_info=[
    ['egon',18,['play',]],
    ['alex',18,['play','sleep']]
]
print(students_info[1][2][0])

 


dict Dictionary kv key-value pairs used to access k v
info={'name':'egon','sex':'male','age':18} info=dict({'name':'egon','sex':'male','age':18})
print(type(info))
print(info['name'])
d = { ' a ' : { ' it ' [1,5,9]}, ' b ' : ' vb ' , ' c ' : ' vc ' , ' d ' : ' vd ' }
 print (d [ ' to ' ] [ ' it ' ] [2])

 



bool Boolean value determination
# Arithmetic 
RES =. 1 +. 3
Print (RES)
Print (. 1 +. 3)
Print (10 /. 3) # Results decimals part
print (10 // 3) # leaving only the integer portion of the
print (10% 3) # take the remainder
Print (2 **. 3)

# comparison operation: == => <> = <=!
# knowledge of:
may compare the size between each digital #
Print (10>. 3)
Print (10> 3.1)

# string but only You can compare the size of the character string (the character corresponding to the position according to the ASCII table to compare the reference)
MSG1 = 'Hello'
Msg2 = 'Z'
Print (MSG1> Msg2)

# a-Za-Z
Print ( 'a'> 'the Z' )
Print ( 'the Z'> 'the Y')
Print (len ( 'Hello')>. 3)
Print ( 'a'>. 3)

# list can list comparison with the size (in accordance with the order corresponding to the value of the position comparison, the corresponding position value must be the same type)
L1 = [l, 2,3]
L2 = [10,]
Print (L2> L1)
L3 = [10,2, 'B',. 3]
L4 = [10,2, 'B', 'C']
Print (L3> L4)




# assignment operator
18 is = Age
# incremental assignment
Age Age + = # = Age +. 1. 1
Print (Age)

# chain assignment
X = 100
Y = X
Z X =

X = Y = Z = 100
Print (ID (X), ID ( Y), ID (Z))

# intersecting assignment
m = 1000
n-= 2000

# TEMP = m
# m = n-
# n-= TEMP
n-, m = m, n-
Print (m, n-)

# decompression assignment
salaries = [11, 22,33,44,55,]
MON1 = ual relations [0]
MON2 = ual relations [. 1]
MON3 = ual relations [2]
MON4 = ual relations [. 3]
MON5 = ual relations [. 4]
MON1, MON2, MON3, MON4, MON5 = ual relations
Print (MON1, MON2, MON3, MON4, MON5)

# equals the number of values included in the right left operand must be consistent with the number of variable names
MON1, MON2, MON3, MON4, MON5, MON6 = ual relations
MON1, MON2 , MON3, MON4, ual relations =

_ = 3333
Print (_)
mon1, mon2, _, _, _ = salaries # underlined eventually assigned 55
MON1, MON2, * _ = ual relations
Print (MON1)
Print (MON2)

ual relations = [11,22,33,44,55,]
First = ual relations [0]
Last = ual relations [. 4]

First, _, _, _, = Last ual relations
First, * _, = Last ual relations
Print (First)
Print (Last)

`` `

### logical operations

` `` Python
Age 20 is =
Sex = 'FEMALE'
# logical operators
# and: connecting the left and right two conditions, only the final result in the case where the two conditions are true only for the True
Print (Age> 18 is and Age <26 is and Sex == 'FEMALE' . 1 and>. 3)

# or: connecting the left and right conditions, whenever a condition is established for the final result True
Print (. 1>. 3 or 2>. 4 or 'X' == 'Y' or ==. 1. 1)

# Not
Print (Not. 1>. 3)
Print (Not (. 1>. 3 or 2>. 4 or 'X' == 'Y' or ==. 1. 1))

res=(3>4 and 4>3) or (1==3 and ('x' == 'x' or 3 >3))
print(res)
```

Guess you like

Origin www.cnblogs.com/liouk/p/11116456.html