26. Job

Digital Type:

Integer (int) and floating point (float)

Integer (int)

Role: represents an integer (such as a person's age, number, etc.)
Definition method:
age1 = 18 
age2=int(18)
print(type(age))
print(age1)
print(age2)
Usage: it can be used for addition, subtraction, logical judgment
x=1 y=2
print(x//y)#取整

Float (float):

Action: a numerical value with a decimal (eg: weight, height)
Definition method:
salary = 2.1  # salary=float(2.1)
print(type(salary))
print(salary)
Usage: addition, subtraction, logical judgment (greater than, less than)
x=1.5 y=float(2.1)
print(x+y)#取整

String type: (str)

Action: represents a value (eg: hobby)

The method defined: string is a string of characters are strung together, wrapped in single quotes, or three double quotation marks a string of characters. Note that: three characters in quotation marks can newline, and characters in single or double quotation marks does not work

name = 'lisa'
username = "toyo"
your_name = """saft
kittll"""
print(name)
print(username)
print(your_name)

Instructions:

1. The string of splicing, i.e., re-apply a small space copy both strings after splicing

2. If there are marks within a string, the string inside the quotation marks and wrapping string can have the same

3. multiplication strings are only multiplying digital

4. string size comparison, comparing the ASCII code

The comparison string is the order of the letters

List: (list)

Role: store multiple values

The method defined: separated by commas any type of value within [].

hobby = 'read'
hobby_list = [hobby, 'run', 'dance']
print(type(hobby_list))
print(hobby_list)

Usage: Method list index value, bearing in mind the index number from 0

hobby_list = ['read', 'run', 'dancel']
# 索引序号      0       1      2
# 取出第二个爱好
print(hobby_list[1])

Dictionary: (dict)

Action: accessing a plurality of values, in accordance with the key: the stored value by value, when not taken by the index key value to, has a function key on the descriptive value.

The method is defined: {} in the plurality of elements separated by commas, each element is key: value format, the format in which the value is an arbitrary data type, since the key has a function descriptive, it is usually a string key Types of

Usage: dictionary index value no longer depends on the way, but rather on the key, to obtain the value corresponding to the key value through the [key]

user_info = {'name': 'toty', 'gender': 'male', 'age': 19, 'company_info': {
    'c_name': 'oldboy', 'c_addr': 'shanghai', 'c_num_of_employee': 50}}

print(user_info['name'])
print(user_info['company_info']['c_name'])

Building word cloud:

Guess you like

Origin www.cnblogs.com/shaozheng/p/11413479.html