Python3 data type, python3 Data Type

Source: Internet
Author: User

Python3 data type, python3 Data Type

1. Basic Data Types
Numeric type
Integer int
Float
Boolean bool: True = 1, False = 0
Complex Type complex
Arithmetic Operator +-* // % **
Assignment operator + =-= * =/= // = % = ** =
Built-in functions max () and min () are used to calculate the maximum and minimum values.
Import decimal


2. Sequence type
'''
# String str, list, And tuple
# Sequence creation and type conversion
# Create a string: single or double quotation marks, three quotation marks, but must appear in pairs
# Create a list: [] brackets separated by commas
# Creating tuples: () parentheses, or comma-separated items
'''
Ss = 'Hello world'
List1 = [1, 3, 5, 7, 9]
Tp = 1, 2, 3, 'A'

3. type conversion
# Length of built-in function len ()
# Sequence type features: Each element in a sequence has a character number, also known as an index.
# Each element has its own index value, with both forward and reverse indexes,
# Forward index indicates that the index value of an element starts from 0 by default from left to right.
# General sequence operations:
# Using indexes for values and slices

# Addition: only the same type can be added +
# Repetition: sequence * number of repetitions
# Check the Member: in, not in to determine whether the element is in the sequence.

 

4. List methods and attributes
'''
L. append (obj) adds a new object to the end of the list.
L. clear () clears the entire list.
L. copy () copy list, which is similar to the replication method of L.
L. count (obj) counts the number of times an element appears in the list.
L. extend (seq) expands the original list with the new list.
L. index (obj) finds the index location of the first matching item of a value from the list.
L. insert (index, obj) inserts an element. You can specify the position.
L. pop (obj = list [-1]) to exit the stack. You can specify the position.
L. remove (obj) removes the first specified element from the left.
L. Elements in the reverse list of reverse.
L. sort () sorts the original list.
'''
Ls = [3, 1, 6, 7, 5, 4]
Ls. append (12)
Ls. reverse ()
Print (ls)

5. variable objects and immutable objects
# Variable objects: List, dictionary, and set
# Immutable object: String, tuples, and numeric type

Related Article

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.