Python Basic concepts

Source: Internet
Author: User

1. Printing: print "HelloWorld" (in version 3.0 of the interview print () Form)


2. Arithmetic: Remove the basic "+-*/%", there are "//* *" two symbols:"//": Is the pick -up"* *": is factorial 3.Python of the number, you can use the float (), int () and the like to convert, of course, you can directly write the floating point type of data 4. About strings:print "Hel\" Lo "cannot use similar characters in characters," such as can cause misunderstanding, if you need to use \ To convert the characters

print "Hello" * 3 characters China multiplication sign can be repeated

print len ("Hello") len () can get the length of the character

Print int ("3") + 3 int () converts numeric characters into plastic

Print str ("3") + "haha" str () can convert numbers into characters 5. Indexing and slicing of strings
print "Hello" [-1] (index last character)
"ABCDEFG" [1:3] slices: This slice operation uses two indexes, the first one is the starting index (inclusive) of the part to be taken, the second is the end index (not included) to take the part, or the two indexes are imagined as the left closed right open interval in set theory.
print "ABCDEFG" [: 3]print "ABCDEFG" [3:]print "ABCDEFG" [:]
If the first element of a slice is the first element of the string, the first index can be omitted, and the second index can be omitted if the slice is to be taken to the end of the string.
Invert: a = "Seabrea"

print A[6:] + a[5:6] + A[4:5] + A[3:4] + A[2:3] + A[1:2] + a[0:1]  6.listindividuals feel similar to arrays, and many methods are similar to strings, such as: Slices
A = [1, 2, "Hello", "Python", [1, 2, 3]]print a
At the same time AH:
A = [1, "2", [3, 4]]

A.insert (1, "H") inserts the character "H" at position 1
A.append (9) add 9 at the end
Del a[0] Delete 1th member

Print a
7. Tuples
A = (1, 2, 3)   is similar to list, but the contents of the tuple cannot be modified or added or deleted.
8.dict

Python provides another form of data structure for key-value storage dict, and we can define our own key to index the entire dict. The form of the dict is also simple, with the colon separating key and value within the curly braces:
Contacts = {"Lilei": "0101234", "Hanmeimei": "0101221365"}print contacts["Hanmeimei"]

Since dict does not require indexes to be contiguous numbers, some of our basic operations are not the same as lists, and we can directly use the index to insert, delete, and change operations, such as:
Contacts = {"Lilei": "0101234", "Hanmeimei": "0101221365"}

#插入
contacts["Lucy"] = "0108754696"

#更改
contacts["Lilei"] = "0105689741"

#删除
Del contacts["Hanmeimei"]
Contacts = {"A": {"B": 1, "C": 2}}
Print contacts["A" ["B"] multidimensional

Python Basic concepts

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.