Python Automation-Language basics-data type and type conversion

Source: Internet
Author: User

What are the core data types in Python?
Variables (numbers, strings, tuples, lists, dictionaries)

What is the immutability of data? Which data types have immutability
The immutable data means that the data cannot be changed, such as:

1 a = ("ABC"# defines tuple 2 a[0]=234  #  Change the first bit to 3453Print (a)  # error when printing

Immutable: Numbers, characters, tuples
mutable: Lists and dictionaries

Common data types in Python

Assign value

1 counter = 2 miles = 3"nan"  4print(counter , Miles,name)  5  6 a = b = c = 1 7 a,b,c=1,2,"nan"  8
   
     9 
    Two number of values interchange assignment there are two methods: the first is to introduce a third variable, and the second is the following 
    ten , B = b,a
   

String

Print (" string, use more ") ' Ilovepython ' Print (S[0:5]) Print ' Nan ' )print(S * 2)

List

1 Print("list, with more")2List = ['ABCD', 123,2.23,678,the Nan"]3Tinylist = [123,"Nan"]4 Print(list)5 Print(list[0])6 Print(List[1:3])7 Print(list[2:])8 Print(tinylist*2)9 Print(list+tinylist)#put it in a listTen  OneList = ["Jia", 3764] ALIST[1] ='Lala' - Print(list)
1 the list is converted to a string: 2 "' . Join (list) 3 Print (Type (list))  #  45 How do I invert a ABCDE string into a EDCBA?  6 str = ABCDE7print(str[::-1])

Meta-group

Print (" Ganso is similar to list, different is ganso with () and cannot be assigned two ")2 tuple = ("abcd" , 123,3.45)#  tuple[1]= ' nan '  tuple is an illegal application

Dictionary

1Print("Dictionary")2 Dict = {'name':' Nan','Code': 798,}3Print(Dict.keys ())4Print(Dict.values ())5Print(Dict.get ("name","Not found"))6Print(Dict.get ("Namet","Not found"))#find the value of key namet in the dictionary if there is no key to print not found, or if there is a key value to print the corresponding

Common data type conversions

1 " "2 Int ()3 str ()4 list ()5 dict ()6 " "7A = 1008 Print(' Nan'+Str (a))9Stre ='1111'Ten Print(Type (len (stre)))#len is of type int One Print("Print Length"+str (Len (stre)))

Remove the specified element from the list below

1L = [2[' GOOGLE',' APPLE',' LINUX'],3['Python','Java','PHP','C'],4['Jack','Tom','Peter']5 ]6 Print(l[0][0],l[1][1],l[2][2])7 " "Print Result: Xiaomi Java Peter" "

Python Automation-Language basics-data type and type conversion

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.