Python beginner's notes (1) and python beginner's notes

Source: Internet
Author: User

Python beginner's notes (1) and python beginner's notes

On the first day of learning python, I hope I can truly understand the computer language and make some achievements.

 

Write down study notes, record learning progress, entertain and learn, and keep growing.

 

Python details:

 

What is python? Where can I use it? What are using it?

Python is a programming language that can be used in various scenarios. It is mainly used by many large companies in network programming. Such as web development and crawler... Large-scale website development: YouTube, zhihu, BT, and Google .. And other large websites are using it.

 

Python is not suitable:
1. Code close to hardware (preferred C );
2. Mobile Development (OC, Swift, and Java );
3. Game Development (C/C ++ );

Why is it so popular?

Many class libraries, simple, and many application scenarios. linux comes with python. You can use python for various interfaces and occasions.

 

There are many python versions.

There are many types such as Cpython, Jpython, and RYRY. In short, Cpython is written in C language, and Jpython is written in java... What does this mean? That is to say, at the beginning of the development of computers, the programming language appeared to be the machine language, in order to understand the machine language-> assembly language-> C language-> advanced language. Advanced languages include C ++, C #, java, and python .. And so on, why is there a higher level than the C language? It is because the C language requires programmers to write computer memory processing, so it is troublesome. Then a higher level language is born, A high-level language means that programmers don't need to worry about memory. You just need to write the program. Early C language compilation can only be compiled into a machine language. For the sake of portability, advanced languages have their own virtual machines. For example, java has a java virtual machine, which is used to compile advanced languages, it is also a means for porting to various systems. Therefore, python also has virtual machines. It can run only when compiled into bytecode and then compiled into machine code. Therefore, python runs slowly than the C language. However, the speed of programming in programming is usually related to the quality of the Code.

 

Python Basics

I. Integer

Python can process Integers of any size, including negative integers. in Python, the expression of integers is the same as that in mathematics. For example:1,100,-8080,0And so on.

Because the computer uses binary data, it is convenient to use hexadecimal to represent integers.0xPrefix and 0-9, a-f, for example:0xff00,0xa5b4c3d2And so on.

Ii. Floating Point Number

A floating point is also a decimal point. It is called a floating point because the decimal point position of a floating point is variable according to the scientific notation. For example, 1.23x10 ^ 9 and 12.3x10 ^ 8 are equal. Floating point numbers can be written in mathematics, such1.23,3.14,-9.01And so on. However, for large or small floating point numbers, we must use scientific notation to represent 10 with e, and 1.23x10 ^ 9 is1.23e9, Or12.3e8, 0.000012 can be written1.2e-5And so on.

Integers and floating-point numbers are stored in computers in different ways. Integer operations are always accurate (is Division accurate? Yes !), Floating-point operations may have rounding errors.

Iii. String

The string is''Or""Arbitrary text, such'Abc',"Xyz"And so on. Please note that,''Or""It is only a representation, not a part of the string. Therefore, the string'abc'Onlya,b,cThese three characters.

Iv. Boolean Value

The Boolean value is exactly the same as that of the Boolean algebra. A boolean value has onlyTrue,FalseEitherTrue, Or yesFalseIn Python, you can directly useTrue,FalseBoolean value (case sensitive) can also be calculated using Boolean operations.

Boolean value can be usedand,orAndnotOperation.

andOperation and operation. Only True is used for all operations, and True is used for the operation.

orThe operation is or. If either of them is True, or is True.

notThe operation is not an operation. It is a single-object operator that converts True to False and False to True.

5. null values

A null value is a special value in Python.None. None cannot be understood as 0, because 0 is meaningful, and None is a special null value.

In addition, Python provides multiple data types, such as lists and dictionaries, and allows you to create custom data types.

 

PrintThe statement can output the specified text to the screen. For example, to output 'hello, world', use the Code as follows:

>>> print 'hello, world'

Note:

1. When we write code in a Python interactive environment,>>>Is the prompt of the Python interpreter, not part of the code.

2. When writing code in a text editor, do not add the code yourself >>>.

The print statement can also keep up with multiple strings separated by commas (,) to form a string of output:

>>> print 'The quick brown fox', 'jumps over', 'the lazy dog'The quick brown fox jumps over the lazy dog

Print prints each string one by one. When the comma "," is used, a space is output. Therefore, the output string is combined as follows:

Print can also print an integer or calculate the result:

>>> Print 300300 # running result >>> print 100 + 200300 # running result

Therefore, we can print the results of computing 100 + 200 more beautifully:

>>> Print '2014 + 100 = ', 200 + 100 + 200100 = 200 # running result

Note:For 100 + 200, the Python interpreter automatically calculates the result 300. However, '2014 + 100 = 'is a string rather than a mathematical formula. Python regards it as a string, please explain the printed results.

 

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.