Python quick learning 02: Basic Data Types & amp; Sequences

Source: Internet
Author: User
Tags python list

Variable does not need to declare the copy code a = 10 # int integer a = 1.3 # float floating point number a = True # True Value (True/False) a = 'Hello! '# String copy code example a = 10 print (a) print (type (a) a = 1.3 print (a, type (a) # built-in function type (), used to query the type of a variable. The following output is 10 <class 'int'> 1.3 <class 'float'> # Another usage of print, that is, print is followed by multiple outputs, separated by commas. Sequence is the most basic data structure in python, a set of ordered objects. Each element is assigned a location that needs to be -- an element, also known as "Index ", the first index is 0, the second index is 1, and so on. Python contains six built-in sequence types: list, tuple, String, Unicode string, buffer object, and xrange object. The main difference between tuple and list is that, once created, each element of tuple cannot be changed, and each element of list can be changed. Example s1 = (2, 1.3, 'love', 5.6, 12, False) s2 = [True, 5, 'smile '] print (s1, type (s1 )) print (s1, type (s2) has the following output (2, 1.3, 'love', 5.6, 9, 12, False) <class 'tuple'> (2, 1.3, 'love', 5.6, 9, 12, False) <class 'LIST'> # s1 is a tuple # s2 is a list Python list. Creating a list interpreter creates a data structure similar to an array in the memory for storage, data item bottom-up members = ['jeff ', 'lil', 'mum', 'Dad '] data List Operation example in the stack copy code members = ['jeff', 'lil ', 'mum ', 'Dad'] print (len (members) print (Members [1]) members. append ('33') print ('members (append): ', members) members. pop () members. extend (['qq','ll ']) print ('members (extend):', members) members. remove ('ll ') print ('members (remove):', members) members. insert (0, 'xx') print ('members (insert): ', members) Copy Code # len () list size # append pop remove insert will have the following output copy code 4 limembers (append): ['jeff ', 'lil', 'mum', 'Dad ', '33'] members (extend): ['jeff ', 'lil', 'mum', 'Dad ', 'qq','ll'] members (remove): ['jeff ', 'lil', 'mum', 'Dad ', 'qq'] members (insert): ['XX', 'jeff ', 'lil', 'mum', 'Dad ', 'qq'] copy other code, if and other operations will use the list, which will be discussed later. Summary # VARIABLES do not need to be declared or deleted. They can be recycled directly. # Sequence # list and operations

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: 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.