Python 01DAY Basics

Python 01 Basics

Video URL: https: //www.bilibili.com/video/av71299046

Video content

  • Preliminary understanding of computer
  • Interpreter installation
  • IDE installation, assembly code software: Pycharm
  • Getting python

Content Details

1. Computer preliminary understanding

Common operating systems

  • win
    • win7
    • win10
    • window server
  • linux
    • centos, graphical interface difference
    • ubuntu, personal development (graphical better)
    • redhat, Enterprise
  • mac, (in the how to play before the entry mac, mac) office

Learn programming language

  • Quasi mounting machine explained compiled
  • Learning grammar

2. interpreter installation

1. Download the interpreter URL: https: //www.python.org/downloads/windows/ 7c6dc30404cbe4c84de973ca15e95a18.png

3. The first script

The first script (a file)

  1. Turn on the computer terminal, a function key + R
  2. Enter the command: path to the script interpreter path (recommended .py suffix)

4. encoding

1. acquaintance coding

graph TD ascii code unicode Unicode Utf-8 code
  • ascii English, 8 represent a thing, 2 ** 8
  • unicode Unicode, 32 represent a thing, 2 ** 32
  • Utf-8 to unicode compression, exhaustion digits represent less of a thing, to 8-bit units

eight byte ASCII 1 = 4 bytes = 32-bit Unicode utf-8 with a minimum of 1 byte = 8 bits, with up to 4 bytes = 32 bits is shown. Chinese: 3 bytes = 24 represents

2.Python interpreter coding

  • Python2: ascii, plus the file header:
# -*- coding:utf-8 -*-

print('你好')
  • Python3:Utf-8

3. file encoding recommendations: When writing a file, save the file to use utf-8 format. What to save coding, it is necessary to open what encoding, or garbled

notepad ++ Download: http: //www.notepad-plus-plus.org/downloads/

6. Interpreter

#!/usr/bin/env python
# -*- coding:utf-8 -*-

print('你好')

Invalid on the system's first line win, only for linux system file: a.py run: interpreter file path has a special method of execution on linux:

  • Give permission to an executable file
  • ./a.py automatically find the first row = / usr / bin / env / python a.py

7. Output

print(你想输出的内容)

Special: py2: print 'Hello' py3: print ( 'Hello')

8. Data Type

'alex'/"李杰"  字符串
666  数字/整型
True/False  布尔类型

1. String

  • apostrophe
  • Double quotes
  • Three marks in the internal text may wrap py

2. 3. Integer Boolean

9. Variable

content='物鱼要刀鱼,刀鱼要到岛上钓'
content=666
print(content)

Requirements variables

  1. Variable names can only contain: letter / number / underscore
  2. The numbers do not begin with
  3. You can not be a python keyword
  4. Suggest
    • See known name meaning: name = "alex" age = 18
    • Underlined the connection: alex dad = "WU"

Supplementary: AlexDad = 'Wu Pei Mika (camel named, not recommended)

10. Exercises

第一题
age = 18
new_age = age+1
print(new_age)

第二题
name = "alex"
new_name = name + 'sb'
print(new_name)

第三题
age = "666"
new_abe = age +"666"
print(new_age)

第四题
age = 666
new_age = age+666
print(new_age)    # 报错

第五题
age = 6
new_age = age * 2
print(new_age)

第六题(特殊)
name="alex"
new_name=name *2
print(new_name)

第七题
age = 18
value = age >=19
print(value)

第八题
_ = 9
gname = 'allex'
True = 9    #错误
print = 666    #错误

11. Enter

user_name = Input("请输入你的姓名:")
message = user_name + "烧饼"
print(message)

Note: the contents of the input water input to get a string of far-py version differences:

  • py2: name = raw_input ( "Please enter your name")
  • py3: name = input ( "Please enter your name")
示例:
user_nane = input("请输入你的姓名:")
password = input("请输入你的出码:")

content="你的用户名是:"+ user_nase+"你的密码是:"+password
print(content)

12. Notes

"" "Multiline comments" "" #-line comment

13. Analyzing conditions

#单项判断
if :
#双向判断
if :
else:
多项判断
if:
elif:
else:

Examples of supplements

#用户名密码登陆
username=input('请输入用户名:')
password=input('请输入出码:')
If username =="alex"and password=="oldboy"
    print('欢迎登陆')
else:
    print("用户名或密码错误")

Guess you like

Origin www.cnblogs.com/haimeinong/p/11833535.html