Python basics _ character encoding and binary, user interaction, python Interaction

Source: Internet
Author: User

Python basics _ character encoding and binary, user interaction, python Interaction

Character encoding

ASCII-supports 255 characters

Gb2312 -- supports more than seven thousand Chinese Characters

Gbk-supports over 20 thousand Chinese Characters

Gb18030 -- supports more than 20 thousand Chinese Characters

UTF-8 -- can automatically adjust the size, English only occupies 1 byte, Chinese occupies 3 byte

The python3 interpreter uses UTF-8 encoding to process files by default.

The Python2 interpreter uses the ASCII character encoding method by default.

Note

Single line comment :#

Multi-line comment: either ''' or "appears in pairs.

Print multiple rows with 3 single quotes or 3 multiple quotes

1 info = ''' 2 name: Lily 3 age: 22 4 adr: fj 5 ''' 6 print (info) 7 8 Results: 9 name: Lily10 age: 2211 adr: fj
Print multiple rows

Single or double quotation marks can be used to print a single line. The printed characters must contain single quotation marks.

User input

The default input data is str by default.

For Python 2, raw_input is used.

In pyhton3

1 name = input ("name:") 2 age = input ("age:") 3 print ("personal information:", name, age) 4 result: 5 name: lily6 age: 227 personal information: Lily 22
User input
Name = input ("name:") age = input ("age:") info = ''' ------ info is ''' + name + ''' ------ name: ''' + name + ''' age: ''' + age + ''' print (info) name: Lilyage: 20 ------ info is Lily ------ name: lilyage: 20 ps: Multiple blocks of memory will be opened, not recommended
User input (+ connector)
Name = input ("name:") age = input ("age:") info = ''' ------ info is % s ------ name: % sage: % s ''' % (name, name, age) print (info) Result: name: Lilyage: 10 ------ info is Lily ------ name: Lilyage: 10
User input (% s placeholder)
Name = input ("name:") age = input ("age:") info1 = ''' ------ info is {_ name} ------ name: _ nameage: _ age '''. format (_ name = name, _ age = age) print (info1) info2 = ''' ------ info is {0} ------ # {0} is not objective name: {0} age: {1 }'''. format (name, age) print (info2) Result: name: kuage: 99 ------ info is ku ------ name: _ nameage: _ age ------ info is ku ------ name: kuage: 99
User input (. format)

Import Module

Import getpass

import getpassname = input("My name is ",)pwd = getpass.getpass("login paaaword")print(name,pwd)

 

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.