Python Learning Notes

Source: Internet
Author: User

Liaoche Python Tutorials

How do I run the PY program directly?

# !/usr/bin/env Python3 Print ('Hello,world') $ chmod a+x hello.py

The setup details of the print () function in Python?

# print () prints each string sequentially, encountering a comma "," which outputs a space Print ('a','b','C') a b C 
Print ('a') Print ('b') AB

How does python enter data from the keyboard?

>>> name = input ('input your name:') input your name:lizhixin>>> name ' lizhixin '

How do I set the tab in notepad++ to 4 spaces?

set = = preferences and TAB settings

How to set force not escape?

>>> r'\n\r\t'\\n\\r\\t'

The result of variable assignment in Python?

>>> a = 3>>> B = a>>> a = 4>>> b3

Basic knowledge of character encoding?

# the computer will only process numbers, and any text will eventually be converted into numbers to get into the CPU engagement operation. # 8 bit (bit) = 1 byte (bytes) # International encoded Unicode, converted to ' variable length encoded ' UTF-8, using Unicode in memory, to be transferred and stored to the hard disk is saved as UTF-8

How do I get an integer representation of a single character? How do I convert the encoding to the corresponding character?

>>> Ord ('l')108>>> ord ('#') 35>>> chr (123)'{'>>> chr (20013)'  in '
# the string type of Python is STR, which is expressed in Unicode in memory, and one character corresponds to several bytes. If you want to transfer on the network, or save to disk, you need to turn str into bytes in bytes. 

How to convert str to bytes?

' lizhixin '. Encode ('ascii') b'lizhixin'  Li Zhixin '. Encode ('utf-8') b'  \xe6\x9d\x8e\xe6\xb2\xbb\xe9\x91\xab'

How to convert bytes to str?

>>> b'grge'. Decode ('ascii')' Grge '>>> b'\xe6\x9d\x8e\xe6\xb2\xbb\xe9\x91\xab'. Decode ('  utf-8')' Li Zhixin '

How do I format an output string?

' Hi,%s, you have $%d. ' % ('lizhixin', 10000000)'Hi, Lizhixin, you have $ 10000000.'

What are some common data structures for Python?

# list>>> a = [1, 2, 3]>>> a[1, 2, 3]#  tuple of tuples & Gt;>> B = 1, 2, 3>>> B (1, 2, 3)#  dictionary dict>>> c = {1:2, 3:4, 5 : 6}>>> c{1:2, 3:4, 5:6}#  Set Set>>> d = {1, 2, 3, 4}>>> d{1, 2, 3, 4}

What kinds of loops do python have?

>>> a = [1, 3, 5, 7, 9] for in A:    print(num)     13579
>>> n = 0 while n <=:    print     (n)= n + 1 C16/>012345678910

What are the operations of dictionaries in Python?

# It's hard to write right at once, {}, [], ', one can't be wrong >>> names = {'micheal'Bob c7> 'Tracy': names[>>>'micheal ' ]95

Python Learning Notes

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.