day 004 jobs

The role of the five data types Python 1. Briefly, the defined manner using the method:

  1. Digital Type

    Integer:

    Role: represents the person's age, all kinds of numbers, level

    Use:

    x = 1
    y = 2
    print(x + y)
    print(x - y)
    print(x * y)
    print(x / y)
    print(x % y)  # 取余
    print(x // y) # 取整
    print(x ** y) # 幂

    Definition method:

    age=18
    age=int(18)

    Float:

    Role: represents the height, weight, payroll

    Defined method:

    salary=3.2
    salary=float(3.2)

    Instructions:

    + - * / % // **
  2. String type

    Role: represents the name of hobbies

    definition:

    name='nick'
    int_str=str(123)

    Instructions:

    Self string comparison logic + *

  3. List

    Action: storing a plurality of (of any data type) element

    Definition: a plurality of spaced elements (of any data type) with a comma in []

    Instructions:

    hobby_list=['read','run','girl']
                   0      1     2
    print(bobby_list[1])
  4. dictionary

    Action: storing a plurality of values, each value by the description but

    Definition: {} the plurality of keys separated by commas (described, string): the value (a specific value, can be any data type)

    Instructions:

    user_info={'name':'nick','gender':'male','age':19}
    print(user_info['name'])
  5. Boolean

    Effect: Conditions for determination result

    Definitions: True, False usually not directly quoted, required logic operation result obtained

    Instructions:

    print(type(True))
    print(True)
    print(bool(0))
    print(bool('nick'))
    print(bool(1 > 2))
    print(bool(1 == 1))

    2. The following line of code to implement the functions of the code implementation:

x = 10
y = 10
z = 10
x=y=z=10

3. Write two ways exchange x, y values:

x = 10
y = 20
#第一种
m=x
x=y
y=x
#第二种
x,y=y,x

4. Remove the line of code nickof 3 interests:

nick_info_dict = {
'name':'nick',
'age':'18',
'height':180,
'weight':140,
'hobby_list':['read','run','music','code'],
}
print(nick_info_dict['hobby_list'][1],nick_info_dict['hobby_list'][2])

5. Use the formatted output of three ways to achieve the following outputs (name changed to his name, acquired modify height and weight, do not brazen)

name = 'Nick'
height = 180
weight = 140

# "My name is 'Nick', my height is 180, my weight is 140"
print(f'My name is {name},my height is {height},my weight is {weight}')
print('My name is {},my height is {},my weight is {}'.format(name,height,weight))
print('My name is %s,my height is %d,my weight is %d'%(name,height,weight))

Guess you like

Origin www.cnblogs.com/zqfzqf/p/11497882.html