Python Learning Note One: First python program, variable, character encoding with binary, user interaction Program

Source: Internet
Author: User

First Python program

Windows: Setting environment variables, X:\PTHONXXX,XXX is the version number

At the command prompt

Enter Python, enter interpreter

>>>print ("Hello world!")

>>>exit ()

Edit File helloworld.py

Execution: Python helloworld.py

Linux:./helloworld.py declaration interpreter: #!/usr/bin/env python looking for python in environment variables

Chmod 755 helloworld.py

Variable

Pycharm

Settings-editor-file and Code Templates-python Script: Setting environment variables, UTF-8 encoding, author, etc.

Variable declaration in Shell = cannot have spaces before and after

The string variable points to an address, so

Name= "Test"

Name2=name

Name= "Test1"

Name2 is still "test".

A variable can only be combined with characters, numbers, and lines, the first character cannot be a number, and the keyword cannot be a variable name.

Variable names are made up of meaningful words, and the words are separated by _

There is no constant concept, the use of capital letters to denote constants, should not be changed

Character encoding and Binary

Use smoke signals to describe the binary principle in a more accurate example of a large number of enemies, very image

Can be calculated at the python prompt, 2**8 refers to 2 of the 8-time Square

ASCII: 8 bits for a character (1 bytes), a total of 28-1 = 255 characters, ASCII characters can be entered with ALT + keypad numeric key, English letter + special characters use 128 (0-127) bytes.

Use the remaining character space as an index, representing more than 7,000 characters and characters, this is GB2312; expanded to more than 20,000 Chinese characters and graphic symbols, this is GBK; it contains 27,000 Chinese characters and the main minority characters, GB18030. The embedded device is not required, so mobile phones, MP3 generally only support GB2312.

The ascii,gb2312,gbk,gb18030 are all backwards compatible, and the gb2312,gbk,gb18030 belong to the double-byte character set.

GBK is usually used to refer to Chinese.

Unicode (Universal code), with characters occupying 2 bytes (16bit).

UTF-8, variable-length Unicode, English 1-byte, European-character 2-byte, East Asian font 3 bytes.

User interaction Program

Comments

# single Comment

"Multi-line Comment"

Use three ' to represent multiple lines of string

Single-line strings with ' or ' Can, ' and ' can be applied to each other.

There is a difference in the single quotation mark in the shell, and the ' in $ ' is escaped.

User input

Input (),

Using read in the shell

Python2 is what format is accepted by Raw_input,python2 input, do not use

Referencing an external variable in a string

A. String concatenation, variable default to str type, converted to number int (), convert string str ()

B. Using%s,%d (integer),%f (floating point), and external with% (variable name,...)

Use type (variable) to view variable types

C. Use the _ variable name as an internal variable, using. Format (_ Variable name = variable name,...) The way reference

D. Using {0},{1},...,. Format (variable name 1, variable name 2,...) The way

Hide Password

Importing modules Import Getpass

In class, the teacher said in the pycharm can not be used in Pycharm2017 in the use of.

Python Learning Note One: First python program, variable, character encoding with binary, user interaction Program

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.