Python---basic data types

Source: Internet
Author: User

1 Basic data types

What is data?

x=10,10 is the data we want to store.

2. Why the data is divided into different types

Data is used to represent States, and different States should be represented by different types of data.

3. Data type

Numbers (shaping, long-shaped, floating-point, plural)

String

List

Meta-group

Dictionary

Collection

Introducing the bytes type when introducing character encodings

Number: 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, triple), consisting of a string of characters (descriptive data): Name, gender, address, education, password: alex3714

Name= ' Egon '

Value: First of all, it is clear that the string as a whole is a value, except that it is unique: Python does not have

Character type, the string is composed of a string of characters, you want to remove the characters in the string, you can also follow the

Subscript the way to get

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: Included in [], separated by commas open 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]

Add 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:alex

Sex:none

age:81

Hobby:zsb00 zsb1 zsb2 zsb3 "" "

#name Sex Age Hobby

student_info=[' Alex ', none,81,[' zsb0 ', ' zsb1 ', ' zsb2 ', ' Zsb30 ']

STUDENT_INFO[3][2]

Dictionary: use: To store multiple values, which is the same as the list, and the value can be any data type feature: Each value is a one-to-one correspondence, i.e. key, which emphasizes that key must be

Immutable types: Strings, numbers

student_info={

' Age ': 81,

' Name ': ' Alex ',

' Sex ': None,

' Hobbies ': [' zsb0 ', ' zsb1 ', ' zsb2 ', ' Zsb30 ']}

Action: View

>>> student_info={

... ' Age ': 81,

... ' 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 ' > True

>>> pinfo[' sex '] = = ' Female ' True

Python---basic data types

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.