Python learning day1, python learning day1

Source: Internet
Author: User

Python learning day1, python learning day1

 

1. Install the python Environment

1. Download python: (3.5.1 and 2.7.11 are available)

Address: https://www.python.org/downloads/ (recommended official website download)

The downloaded python contains pip for managing python (the package tool for managing python), so you do not need to download it separately.

2. Download and compile Python IDE

(1). windows: PyCharm (many types, I use Pycharm or sublim

(2). Linux and Mac OS: open terminal and enter python to enter the code writing interface.

2. Write the first Hello Python

Enter print ("Hello Python") or print "Hello Python" in the code writing interface ('') it can also be ("");

III. Basic Python syntax

1. python identifier

(1) letters, numbers, and underscores (identifiers)

(2) It cannot start with a number.

(3) case sensitive

(4) identifiers starting with "_" have special meanings. They indicate that they cannot be accessed directly. They cannot be accessed directly by using callback class attributes. They must be accessed through interfaces provided by classes.

(5) An identifier starting with "_" k Represents a private member of the class. It starts with "_" and ends with a special method-specific identifier.

2. Reserved characters of python

And exec not assert finally or break for pass from class print

Continue raise return if global def del import try while else in

Is elif with doesn t lamba yield

3. Lines and indentation

The biggest feature of Pyton language is that it does not use braces ({}) to control classes. Functions and their logical judgments are controlled by indentation and rows.

4. multiline connector "\"

Sum = a + \

B ++ \

C

5. python has three single quotation marks (') double quotation marks (""). Three quotation marks (") indicate strings.

6. python annotations

(1) single line # start

(2) In multi-line python, multiple-line comments use three single quotes (''') or three double quotes (""").

7. Empty lines and code groups

Classes and classes are separated by empty lines between functions to enhance readability.

Code group: A group of statements with the same indentation constitute a code block, which we call a code group. Include a complete while statement for the for loop.

Iv. Python variable types

1. assign values to variables using equal signs (=) in python;

2. Data Type

Numbers (number), String (String), List (List ps: array), Tuple (tuples), Dictionary (Dictionary)

(1) Python supports four different numeric types: int long float complex

(2) strings are generally enclosed in quotation marks.

(3) list: list = [1, 2, 3, 4]

(4) tuples: equivalent to a read-only list. The data in the brackets () are separated by commas.

(5) dictionary: statement format {'id': '01', 'age': '12'} Where id and age are called keys ()), where 01 and 12 are key values ())

3. type conversion

(1) int (x [, base]) converts x to an integer.

(2) long (x [, base]) converts x to a long integer.

(3) float (x) converts x to a floating point number.

(4) complex (real [, imag]) creates a plural number

(5) str (x) converts object x to a string

(6) repr (x) converts object x to an expression string

(7) eval (str) is used to calculate a valid Python expression in a string and return an object.

(8) tuple (s) converts the sequence s into a tuples.

(9) list (s) converts sequence s to a list

(10) convert set (s) to a variable set

(11) dict (d) Create a dictionary. D must be a sequence (key, value) tuples.

(12) frozenset (s) to an unchangeable set

(13) chr (x) converts an integer to a character

(14) unichr (x) converts an integer to a Unicode Character

(15) ord (x) converts a character into its integer.

(16) hex (x) converts an integer into a hexadecimal string

(17) oct (x) converts an integer into an octal string

 

  

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.