First meeting with Python and first meeting with Python

Source: Internet
Author: User

First meeting with Python and first meeting with Python

1. Introduction to Python

The founder of python is Guido van Loum. During the Christmas Day of 1989, GDO van rossoum was determined to develop a new script interpreter to pass the time in Amsterdam as an inheritance of the ABC language.

2. What kind of language is Python?

Programming languages are classified from the following perspectives: compiler and interpretation, static and dynamic languages, strong and weak definition languages.

What is the difference between compilation and interpretation?

The compiler compiles every statement in the source program into a machine language and saves it as a binary file. In this way, the computer can run the program directly in the machine language at a high speed;

The interpreter is interpreted as a machine language for execution only when the program is executed, so the running speed is not as fast as that of the compiled program.

This is because computers cannot directly understand and execute the statements we write. They can only recognize machine languages (that is, binary forms ).

Currently, common compiling languages include C and C ++, while interpretation languages include python, php, ruby, and java.

Iii. Advantages and Disadvantages of Python

Advantages: 1. Positioning of Python is "elegant", "clear", and "simple"; 2. High development efficiency; 3. Advanced language; 4. portability; 5. scalability; 6. embeddable;

Disadvantages: 1. Slow speed; 2. Code cannot be encrypted; 3. threads cannot use multiple CPUs

Iv. Python Interpreter

When writing python code, we get a file text that contains the Python code with the. py extension. To run the code, you need the Python interpreter to execute the. py file.

Common python interpreters include CPython, IPython, PyPy, Jython, and IronPython.

V. Python Installation

Windows

1. Download the installation package

Https://www.python.org/downloads/

2. Installation

Default installation path: C: \ Python35

3. Configure Environment Variables

Right-click the computer and choose Properties> advanced system Settings> advanced> environment variables to add python installation Path in Path.

  

6. The first Python program HelloWorld

Windows

Open the command prompt -- input python (enter the python compiler) -- print HelloWorld

    

Linux

Create a file named helloworld. py in linux and enter

      

Then run python helloworld. py and output:

      

VII. programming style

1. Syntax requirements

Uniform indentation (the same level of indentation)

2. Variable-defined rules

The first character of an identifier must be an uppercase or lowercase letter or an underline.

Other parts of an identifier name can contain letters, underscores, or numbers.

The identifier name is case sensitive.

The identifier starting with the following line is of special significance. An underscore (_ foo) indicates that a class attribute cannot be directly accessed through the interface provided by the class.

Start with a double underline (_ foo) indicates the private member of the class; start with and end with a double underline (_ foo _) indicates the special identifier for special methods in python

Variables cannot be declared using keywords.

3. Notes

Single line comment usage :#

      

Use multiline comments: ''' or """"""

8. Character unit and character encoding

1. Conversion between character units

A binary number (0, 1) = 1 bit (bit)

8bit = 1 bytes

1024 bytes = 1 kbytes (kb)

1024kb = 1 MB

1024 MB = 1 GB

1 GB = 1 TB

1 TB = 1 Pb

2. The default character encoding in python is UTF-8.

Declare the character encoding format when writing a python script

# _ * _ Coding: UTF-8 _*_

9. Second python Program

1. input usage

# Perform human-machine interaction through input, and assign the user input information to the variable name. Then print the value of the name variable.

Name = input ("enter your name :")

Print (name)

2. Usage of info Template

#! /Usr/bin/env python

#-*-Coding: UTF-8 -*-

# Author: ye

Name = input ("enter your name :")

Age = input ("Enter your age :")

Job = input ("Enter your hobbies :")

Info = '''

---------- Info of % s ----------

Name: % s

Age: % s

Job: % s

------------- End --------------

''' % (Name, name, age, job)

Print (info)

3. if condition usage

If condition:

Body

Else:

Body

Instance:

#! /Usr/bin/env python

#-*-Coding: UTF-8 -*-

# Author: ye

Core = int (input ("Enter your score :"))

# Determine the score based on the if condition

If core> 100:

Print ("incorrect input. Please enter again ")

Elif core == 100:

Print ("A + ")

Elif core> = 90:

Print ("")

Elif core> = 80:

Print ("B ")

Else:

      Print ("stupid ")

 

Note: python development tool: PYcharm

 

 

  

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.