Python that you don't want to give up

Source: Internet
Author: User

Python section of this section (data type)

1 Basic data types

Digital:
int: grade, age, grade, ID number, QQ number, mobile number
level=10
Float type: Height, weight, salary, temperature, price
height=1.81
salary=3.3

String str: Enclosed in quotation marks (single, double, three), consisting of a string of characters
Use (descriptive data): Name, gender, address, education, password: alex3714
Name= ' Egon '

Value:
First, make it clear that the string as a whole is a value, except that it is special:
There is no character type in Python, the string is made up of a string of characters, you want to remove the character from the string, or you can do so by subscript.

Name: Gets the value that is the whole of the string
NAME[1]: Get the character that is the second place

string concatenation:
   

>>> msg1= ' Hello ' >>> msg2= ' world ' >>>>>> msg1 + msg2 ' Hello World ' >>> res= MSG1 + msg2>>> Print (res) Hello world>>> msg1*3 ' Hellohellohello '



List: contained within [], separated by commas
Use (save multiple values, can be modified): hobbies, equipment, girlfriends
hobby=[' play ', ' eat ', ' sleep ']
Method:
Hobby.append
Hobby.remove
Operation:
View:

>>> girls=[' Alex ', ' WSB ', [' Egon ', ' YSB ']]>>> girls[2][' Egon ', ' YSB ']>>> girls[2][0]



Increase
Girls.append (Element)
Delete
Girls.remove (Element)
Del girls[index of elements]
Modify
girls[0]= ' ALEXSB '

Dictionary dict: defined in {}, comma-separated, each element in the form of a key:value

Student_info= "" "Name:alexsex:noneage:81hobby:zsb00 zsb1 zsb2 zsb3" "#name sex Age hobbystudent_info=[' Alex ', none,81, [' zsb0 ', ' zsb1 ', ' zsb2 ', ' Zsb30 '] STUDENT_INFO[3][2]

Dictionary:
Purpose: Store multiple values, which is the same as the list, and the value can be any data type
Characteristics: Each value is a one-to-one correspondence, i.e. key, which emphasizes that key must be
Immutable types: Strings, numbers

student_info={' age ': Bayi, ' name ': ' Alex ', ' sex ': None, ' hobbies ': [' zsb0 ', ' zsb1 ', ' zsb2 ', ' Zsb30 ']}

Operation:
View

>>> student_info={... ' Age ': Bayi,... ' Name ': ' Alex ',... ' Sex ': None,... ' Hobbies ': [' zsb0 ', ' zsb1 ', ' zsb2 ', ' Zsb30 '] ...} >>>>>> student_info[' age ']81>>> student_info[' hobbies ' [' zsb0 ', ' zsb1 ', ' zsb2 ', ' Zsb30 '] >>> student_info[' hobbies '][2] ' ZSB2 '


Increase
student_info[' stu_id ']=123456

Delete
Del student_info[' stu_id ']

Modify
student_info[' name ']= ' ALEXSB '


Boolean: True False
Purpose: Used to judge

>>> pinfo={' name ': ' Oldboymei ', ' age ': +, ' sex ': ' Female '}>>>>>>>>> pinfo[' age '] > 50true>>> pinfo[' sex '] = = ' Female ' True

Python that you don't want to give up

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.