A New Beginning--python

Source: Internet
Author: User

First week--python Foundation 1. About Python 1.1Python Brief History 1.2 install Python1.3 "Hello World"

Before running the first program "Hello World", let's look at several ways to run Python.

The first one is to open the installed Python3 directly to display the following interface.

  

The second method is to run the WIN+R key combination under the Windows system and enter cmd into the command prompt. Enter Python to see if you are entering a Python environment. interface and consistency. If the display error is not entered, the Python locale is not configured. Open Computer advanced system, environment variable, system variable->path-> enter Python after creating a new path. EXE can be used normally after the address is CMD.

After opening python, enter:

  

#!/usr/bin/env python

Print ("hello,world!" )

Show results

  

This completes the first Python program.

It is also possible to modify a written program file into a. py file directly by clicking Run. #!/usr/bin/env python means declaring the interpreter type. If this statement is not added, the direct execution of Python myfirstpyprogram.py is also possible, because the program has been explicitly called to tell the operating system to use Python to interpret the code, so there is no error.

1.4 Character encodings < references >

Character encoding is the role of computer-recognized binary and human understanding of the popular language to establish a link, so in the process of dialogue with the computer more convenient. Since the computer was invented by the Americans, only 127 letters were encoded into the computer, that is, letters, numbers, and symbols, which are called ASCII encodings, such as uppercase letters encoded in A 65 lowercase letters z 122 . Later the computer world began to have other languages, ASCII code has not been able to meet the demand. Later people in different languages individually customized a set of their own code, while maintaining compatibility with ASCII. These encodings are collectively known as MBCS, where everyone begins to use double-byte. (China's called gb*, such as GBK).

Later people began to think that so many coding, some coding is not compatible, too big head, so a group of people sitting together came up with a way: All languages use the same encoding, this encoding is Unicode. Unicode uses a minimum of 2 bytes (1 bytes =1byte=8bit= A binary number with a length of 8) to represent letters and symbols, and sometimes 4 bytes. This solves the problems encountered above.
Unicode, also known as the Universal Code, is a standard in the industry. But some people think that if I want to represent an ASCII character, using Unicode to indicate that it is not too wasteful, then someone came up with another solution--utf-8.
UTF-8 is the compression and optimization of Unicode encoding, the most important feature is that it uses a variable length encoding, he no longer uses a minimum of 2 bytes, but all the characters are categorized. The contents of the ASCII code are saved with 1 bytes, the characters in Europe are saved in 2 bytes, and the characters in East Asia are saved with 3 bytes ...

GB2312 is the 1980 national development of Chinese characters within the code specification, contains more than 6,000 Chinese characters and symbols, the symbol is limited, the National Standardization Committee has formulated the principle of gb13000,gb13000 and GB2312 different, GB13000 to internationalization as the goal, The standard code refers to the Unicode 2.0 standard encoding, and GB2312 is completely incompatible, because the early computer Hancock adopted GB2312, unable to smooth transition to GB13000, so GB13000 into a paper standard, can not be promoted-; With this experience, The National Standardization Commission has developed the GBK standard, which is compatible with the GB2312 standard, and expands the GB13000-contained words on the basis of GB2312 standards.

1.5 variables

Variables: stored information, later called, modified operation
Constants: Fixed amounts, uppercase letters
Naming rules:
1. Alphanumeric Underline composition
2. Cannot start with a number, cannot contain special characters and spaces
3. Cannot be named with a reserved word
4. Cannot be named in Chinese
5. The variable name defined should make sense
6. Hump-Type life, underline word segmentation
7. Variable names are case-sensitive

1.6 Other

num + = 1 is equivalent to num = num + 1
num-= 1 is equivalent to num = num-1
Num *= 2 equivalent to num = num * 2
Num/= 2 is equivalent to num = NUM/2
Num//= 2 equivalent to num = num//2
Num%= 2 equivalent to num = num% 2
Num **= 2 equivalent to num = num * * 2


And, and
Only if two conditions are all true (correct), the result will be true (correct)


Condition 1 and Condition 2
5>3 and 6<2 True

  

A New Beginning--python

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.