First knowledge of Python

Source: Internet
Author: User
Tags logical operators

First, the introduction of Python

1. First Python program

Enter print (' Hello,world ')

2. File header

  #!/usr/bin/env python

  # -*- coding: utf-8 -*-  3. Comment Line Comment: #注释内容 more comments: "' note content ' ' 4. If you import other. py files when you execute Python code for the PYc file, a. pyc file with the same name will be generated automatically during execution, and the file is compiled by the Python interpreter. Bytes generated after the code. Second, the variable 1. Why variable variables are used to record the state of a program's Operation 2. Declaration and reference of a variable name= ' Sam ' #变量的声明 print (name) #引用并且打印变量名name对应的值 3. Variable name range variables can only be letters, numbers, or underscores The first character of any combination variable name cannot be a number the following keywords cannot be declared as variable names: [' and ', ' as ', ' assert ', ' Break ', ' class ', ' Continue ', ' Def ', ' del ', ' elif ', ' Else ', ' except ', ' exec ', ' finally ', ' for ', ' from ', ' global ', ' if ', ' import ', ' in ', ' was ', ' lambda ', ' not ', ' or ', ' pass ', ' print ', ' Raise ', ' return ', ' try ', ' while ', ' with ', ' yield '] three, only one input output ython3 input, and python2 in the same way as the Raw_input, is the user's input as a string , Python2 also has the command of input, which is what type the user enters, and what type () is saved to see the data type
# !/usr/bin/env python name=input (' Please enter user name:')print(name)

Perform

c:\users\administrator>python D:\python_test\hello.py Please enter your username: Samsam

When entering a password, if you want to be invisible, you need to take advantage of the Getpass method in the Getpass module, namely:

# !/usr/bin/env python Import Getpasspassword=getpass.getpass (' Please enter password:')print(password)

Perform

c:\users\administrator>python D:\python_test\hello.py Please enter your password:123456

Iv. Simple Operators

  

Arithmetic operator: +,-,*,/,%,**,//

Note: The division in Python is a floating-point operation, and/or can be divisible

* * is a power operation, such as 7**2 's operation result is 49

Assignment operator: =,+=,-=,*=,/=,%=,**=,//=

Comparison operator: ==,!=,<>,<,>,<=,>=

Bitwise operator:$,|,^,~,<<,>>

Logical operators: And,or,not

First knowledge of Python

Related Article

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.