Getting Started with Python based learning (a focus)

Python based learning Notes (a)

 

Compiled languages ​​and interpreted languages:

Compiled language: reading the code executed again, typically generate a document such as a C language generated .h files to the computer to execute

Such as: C, C ++, C #, Java, Go

An interpreted language: reading an execution sentence does not generate files

Such as: Python, Javascript, ruby, PHP

 

Python environment installed:

1. Install the python interpreter (that is often said to install python) recommended py3, in 2020 py2 eliminated  // soul

python interpreter installed Address: www.python.org   (Downloads - the Window / MAC / Linux)

Checking the installation process may add python 3.x to Path (environmental settings do not need to follow)

Interpreter environment settings:

Right My Computer, Properties, Advanced System Settings, click Environment Variables (user variables for the current user, the system for all users, it is recommended to set the system user), the system variables inside Path, edit it, the position of the python interpreter installed, coupled with a semicolon (window7)

2. Install the IDE (PyCharm)   // shell

pycharm installation path: www.jetbrains.com/pycharm/download/#section=windows

Recommended download Community Edition (free), students can not run with IDLE

Open, create a new project, set the path to create a project, select existing interpreter (select python.exe location interpreter)

 

Common built-in data types:

Numeric data types: int, bool (True, False), float, complex

Sequence Data Type: immutable: STR (string), tuple (tuple), bytes; Variable: List (list)

Data collection type: set (collection)

Dictionary data types: dict (dictionary)

 

Analyzing the data type of two built-in functions:

type () that is not the parent class is a subclass type, irrespective inheritance; for example: type (123) -> Back <class int>

the isinstance () will be considered a subclass of the parent class type, consider inheritance; example: isinstance (123, int) -> Returns True

 

Common operators:

Note: '/' is, floating point division, '//' is an integer division: rounded bits

 

input Output:

Input: input ()

Output: print ()

 

Branch statement:

1.if else/elif

2. The ternary operator

Example: num = 1 if a> b else 0 // If a> b returns 1, a≤b returns 0

 

loop statement:

1.for i in range(x1,x2)

2.while else /break/continue

 

String str

Format string:

Example 1: template = "% s demand correction move% s"% ( "Novice", "offer",)    

    Format: string% (variable)

Note: If the string is: "% s cell phone battery is 100%," the string has two percent, so use a variable to be wrong, it needs to be changed: "% s cell phone battery is 100 %%"

Advanced usage (using three quoted string line feed operation can be performed, more beautiful print format):

Example 2:. Template = "{0} and {1}" format ( 'google', 'chrom')    

    The format is: 'string' .format (variable)

expand:

template = "{name and {offer}}". format (name = 'students arrived early, and so advise seniors', offer = 'wish to have a graduate school recruit offer')

If you use a keyword parameter format (), then they will point to the value of the parameter name use

 

Str commonly used methods:

1. "xxx" .upper () // string in lowercase to uppercase characters the same, generally used for verification code Ignore case (conversion to uppercase or lowercase simultaneously)

2.“xxx”.lower()    //将字符串里的大写字母转为小写,字符不变,同上

3.“xxx”.isdigit()      //判断字符串是否为数字

4.“xxx”.rstrip()     //去除字符串右边的空格,一般用于登录

5.“xxx”.lstrip()     //去除字符串左边的空格

6.“xxx”.replace(‘老王,‘**’,1)    //替换字符串,从字符串左向右找第一个老王替换成两*号,不写则所有老王都替换,一般用于敏感字体

7.“xxx”.split(‘,’,1)    //分割字符串,从左向右找第一个逗号进行分割(rsplit()从右向左),不写第二个参数找所有的,返回一个列表 

 

常用的公共功能:   

1.len(value)    //计算长度

2.value[i]        //索引  注:最末尾一个的索引也可以为-1,往前依次为-2,-3......

3.value[i1,i2,i3]    //切片(i1≤序列<i2,按i3的步长来取值)  前两个确定范围,后面按步长取

示例:value[-2:]  //去最后两个字符

4399游戏测试工程师--笔试题:

试题:输入一个字符串,请将字符串反转:

           

 

 

小练习:

 

Guess you like

Origin www.cnblogs.com/hhs1998/p/11754183.html