Python study notes download, installation, grammar

Python3 Download


Python3 latest source code, binary documents, news and other information can be viewed at the official website of Python:

Python's official website: https://www.python.org/

You can download the Python documentation at the following link, you can download the document HTML, PDF and PostScript and other formats.

Python documentation Download: https://www.python.org/doc/

pycharm Download


PyCharm Download: https://www.jetbrains.com/pycharm/download/

PyCharm installation Address: http://www.runoob.com/w3cnote/pycharm-windows-install.html

Python Features

  • 1. Easy to learn: Python has relatively few keywords, simple structure, grammar and a well-defined learning curve easier.

  • 2. Easy to read: Python code defines more clearly.

  • 3. Easy to maintain: Python's success lies in its source code is fairly easy to maintain.

  • 4. A wide range of standard library: One of the biggest advantages of Python's library is rich, cross-platform, in UNIX, Windows and Macintosh compatible well.

  • 5. Interactive mode: support interactive mode, you can enter to execute code from the terminal and get the results of the language, interactive testing and debugging code snippets.

  • 6. Portable: based on the characteristics of its open source, Python has been ported (ie to make it work) to many platforms.

  • 7. Scalable: If you need to run quickly for a key code, or want to write some algorithms do not want to open, you can use C or C ++ to complete that part of the program, and then call from your Python program.

  • 8. Database: Python provides an interface to all major commercial databases.

  • 9.GUI Programming: Python GUI support can be created and ported to many system calls.

  • 10. Can Embed: You can embed Python to C / C ++ program that allows users the ability to get your program "script" of.

Keyword


['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']

Note

# Single-line comments
'''
Multi-line comments
'''
"""
Multi-line comments
"""

Number (Number) Type

python digital There are four types: integer, boolean, floating point and complex.

  • int (integer), such as 1, only one integer type, int, long integer expressed without python2 of Long.

  • BOOL (Boolean), such as True.

  • a float (floating-point), as 1.23,3E-2

  • Complex (complex), such as 1 + 2j, 1.1 + 2.2j

String (String)

  • python single and double quotation marks using the same.

  • Tris quotation marks ( '' 'or' '') can specify a multi-line string.

  • Escapes''

  • Can be used to escape the backslash, backslash escapes allow the use of r can not occur. . The r "this is a line with \ n" is \ n will be displayed, not wrap.

  • Literally cascading strings, such as "this" "is" "string" will be automatically converted to this is string.

  • Operator + strings can be connected together, with the * operator repeats.

  • Python strings two indexing methods, starting with 0 from left to right, right to left to begin -1.

  • The string can not be changed in Python.

  • Python is no separate character type is a character string of length 1.

  • Taken string syntax is as follows: the variable [the header: Tail index: step]

str = 'hello world'
print(str)
print (str [0]) # left the first number
print (str [-1]) # number to the right of the first
print (str [0: 2]) # The first two
print (str [1: 3]) # free end of the head containing
print (str * 2) # original string repeated twice
print (str + 'which is spliced') + # used to string concatenation
print (str + '\ n' + '123') # \ n line break
print (r'str \ nstr ') # r let \ n take effect

List

note:

  • 1, List written between square brackets, elements separated by commas.

  • 2, and the same string, list can be indexed and sliced.

  • 3, List can be spliced ​​using the + operator.

  • 4, List the elements can be changed.

list1 = ["acd",123,12j,0.9]
tinylist = [123, 'runoob']
print(list1)
print(list1[0])
print(list1[0:2])
print(list1*2)
print(list1 + tinylist)

Tuple (tuple)

Tuple (tuple) and a list of similar, except that the elements of the tuple can not be modified. Tuple written in parentheses () , the elements separated by commas.

Tuple element type may not be the same

arr = (123,3.3,'qwe2w')
arr1 = (jji ',' KKK ')
print(arr)
print(arr1)
print(arr + arr1)
print(arr[0:2])

note:

  • 1, and the string like element of the tuple can not be modified.

  • 2, a tuple can be indexed and sliced, as a method.

  • 3, note that a special syntax rules configured tuple contains 0 or 1 elements.

  • 4, a tuple can be used for splicing operator +

Set (collection)

Collection (set) by one or more of various shapes composed of overall size, things or objects referred to as element configuration set or member.

The basic function is to test membership and remove duplicate elements.

Can use braces {} , or set () function creates a set of note: Create an empty set must be set () instead of {} , because {} is used to create an empty dictionary.

student = {'adc','123',123,'adc','ac'}
print(student)
if 123 in student:
    print(True)
a = set('zxcvbnm')
b = set('ascvbnm')
print (a - b) # a and b set difference
print (a | b) # a and b of the union
print (a & b) # a and b the intersection
print (a ^ b) # a and b are not simultaneously present in the element

Dictionary (dictionary)

Dictionary (dictionary) is another very useful Python's built-in data types.

List is an ordered collection of objects, dictionaries are unordered collections of objects. The difference between the two is that: among the elements of the dictionary is accessed by a key, rather than by shifting access.

A dictionary mapping type, with dictionaries {} identifier, which is an unordered key (key): Value (value) set.

Key (key) must be immutable.

In the same dictionary, the key (key) must be unique.

dicn = {'name':'lisi','age':18,'salary':333.3}
print(dicn)
print(dicn.keys())
print(dicn.values())
print(dicn['name'])
Published 59 original articles · won praise 33 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_41010294/article/details/103253606