I. Introduction

Source: Internet
Author: User

1.8.1 built-in Atomic Data Types

Python has both main built-in numeric classes (built-in functions, int and float) that implement the Integer and floating point data types.

Other operation is remainder operator% (modulo operation), the operator * * is exponentiation (exponential operation)

The variable variable in Python is not like C + +, Java, the same type of variable can refer to many different types of data

1.8.2. Built-in Collection Data Types:

Lists, strings, and tuples (tuples tuple) is ordered collections that is very similar in general structure but has specific differences.

Sets and dictionaries are unordered collections.

class tables, strings and tuples are ordered collections, sets, and dictionary unordered collections

Object in 1.list,list does not need all the same type


[1,3,true,6.5][1, 3, True, 6.5][1,3,True ,6.5]myList[1, 3, True, 6.5]           


[06myList[0, 0, 0, 0, 0, 0]   

list [1,2,3]*3, which is said to re-copy this [3], with the numpy in the array, * for each element in the arrays multiplied by its constant k

Import NumPy
>>> mylist=[1,2,3]
>>> myList
[1, 2, 3, 1, 2, 3, 1, 2, 3]
>>> Myarray=numpy.array (myList)
>>> myarray
Array ([1, 2, 3])
>>> myarray*3
Array ([3, 6, 9])

The list's operating characteristics, list can be pop and Insert,pop popup is the most at the end of the list of elements. The Remove operation can delete a value from the list directly. () __add__ (), called it Add method, identifier


 >>>  "David"  ' David ' >> > myname =  "David" >>> myname[3]       
' I 'myName*2' Daviddavid 'len(myName)5>>> 

A major difference between lists and strings is so lists can be modified while strings cannot

The biggest difference between list and string is that the elements in the list can be modified, and string cannot

3.Tuple, the data in the tuple cannot be modified the difference is that a Tuple is immutable

Mytuple= (1,true,4.98)

>>> Mytuple
(1, True, 4.98)
>>> mytuple*3
(1, True, 4.98, 1, True, 4.98, 1, true, 4.98)
>>> mytuple[1]=9

Traceback (most recent):
File "<pyshell#17>", line 1, in <module>
TypeError: ' Tuple ' object does not support item assignment

4.Set collection, the elements in the collection do not have duplicates

Element display in 1.set will not be in a certain order, a unordered way:

{3,6,"Cat",4.5,false}{false, 4.5, 3, 6, ' cat '}{3, 6,"Cat",4.5,False}myset{false, 4.5, 3, 6, ' Cat '}>> >                   


>>> Set (mylist)
Set ([1, 2, 3])

Intersection Select the same element from two set seta.intersection (SETB)

5. Dictionary: Dict.items (): Get a dictionary of each type of element, Dict.get (k,0), from the dictionary has k get K, no words returned to 0

I. Introduction

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.