Preview of the first chapter notes

The first day of rehearsal video notes

Computer Basics

  1. Computer Organization
    • Hard disk memory, CPU input and output devices
  2. What is the operating system
    • Control computer work processes, software
  3. What is the application procedure
    • Software installed on top of the operating system is the application

to sum up

cpu brain

Memory temporary memory

Hard drive permanent memory

The operating system controls the computer hardware work processes

Software applications installed on top of the operating system

About python

The difference python2 and python3

python2 source code is not uniform repeat

python3 no unified source code duplication

What python programming language

Compiled and interpreted, static and dynamic languages, strongly typed and weakly typed language Definition Language

Compiled

  1. Advantages: run fast

  2. Cons: Slow development efficiency / low

Interpreted

  1. Pros: fast development efficiency
  2. Cons: Slow speed

Advantage of the Python language

Getting started is easy simple and clear positioning drill down can write very complex program

Development of high efficiency, a strong third-party libraries

High-level language

portability

Scalability

Embeddable

Getting python

  1. Output: Use Windows systems use notepad ++ to create a text

    print("hello world")

    Then open start to finish save + R and then enter the command python .py file name

    Note: python and file names with spaces are print () the contents of the braces is to be output, if it is caused by the need to words and letters, numbers written in direct quotes.

    python2 wording: print 'hello world'

    python3 writing: print ( "hello world")

    Chinese: print ( "Hello World")

    And then save, save in the terminal run once, followed by being given a

    conding: utf-8 this sentence added to the first line of the file, the file appears time to tell the Chinese use utf-8 encoding to view it

variable

  1. What is variable

    Intermediate variable is to present the results of running a temporary memory for subsequent use Code

    name = "meet"

    This is the definition of a variable

    2. What is it defined variables

    name 是一个变量名
    =    是一个赋值操作 赋值就是将值交给name
    "Meet" 是一个值

    The role of variables: nickname, is on behalf of that the contents of a memory address

Variables defined rules

  • Variable names consist of letters, numbers, underscores
  • Prohibit the use of variable name starts with a number
  • Prohibit the use of the name Python keywords and built-in functions

Keywords are as follows:

['Flase','None','True','and','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']
  • We do not recommend the use of Chinese and Pinyin
  • Variable name to have meaning
  • Variable names are case sensitive
  • Recommended wording:
    • Hump ​​body: AgeOfOldboy = 56
    • Underline: age-of-oldboy = 56

Assignment of variables

name1 = 'Meet'
name2 = 'Guo'

Small advanced variable

age1 = 18
age2 = age1
age1 = 12
age3 = age2
print(age1,age2,age3)

age1 = 12 ,age2 = 18 ,age3 = 18

The code is executed from top to bottom, and a memory with only the same label name.

age = 12
age = 12 + 1
age1 = age + 1
print("我今年:",age1)
name1 = 'alex'
name2 = name1
name1 = 'wusir'
name3 = name2
打印name1,name2name3分别对应的值是什么
name1 = wusir name2 = alex name3 = alex

Results: the code is executed from the top down, and only have one notes, corresponding to the variable name refers to a value only substituting

constant

Constant is the variable name in uppercase, try to maintain a volume does not change, such as ID number, date of birth, etc. ... in the code, it should have some of these things, do not let anyone set at the beginning of change, so this thing is constant.

Note

Code written in relatively classic or too complex, a glance out the need explanatory notes.

# 这个就是给这一行进行注释,注释后的代码不会执行
'''
这种就是多行注释,什么是多行注释,其实就是注释的内容可以进行换行
'''

1561983818590

Basic data types:

Data Type: Computer silly, can not tell the difference between 1 and "Chinese", so in each programming language will have a data type called something, in fact, a variety of commonly used data were clearly divided, first say three kinds of numbers, strings, Boolean

int is plastic; that is, integer math we grew up in contact, the plastic in a computer to calculate and compare transport

int 32-bit range of the machine is: -2 - 31 ** 2 ** 31-1, i.e. -2147483648 2147483647

Int 64-bit machines are: -2 to 2 ** 63 ** 63-1, i.e. -9223372036854775808 ~ 9223372036854775807

Note that these are integers, which currently numbers sufficient for you.

Plastic

num1 = 2 
num2 = 3
print(num1+num2)
# 结果: 5 
# 整形就和我们学的数学一样可以进行加减乘除

str is a string; and Sue Ni can not tell the Chinese, we have to let the Chinese written into it, to follow a rule so that the computer can recognize, as long as this rule is in quotation marks is a string; in python, who quotes, and full of character.

Characters can use single quotes, double quotes, or a three-quotation marks, there is no difference, but some special formatting needs without quotation marks such as

msg = "My name is Alex,I'm 22 years old!"这个就需要单双引号配合。
msg = 
'''今天我想写首小诗,
来歌颂我的同桌,
你看他那乌黑的短发,
好像一只炸毛鸡。
'''
想写多个内容还需要使用换行的时候,就需要三引号。

String

String addition

#字符串的拼接
s1 = 'a'
s2 = 'bc'
print(s1+s2)

String multiplication

str*int name = "坚强"
print(name*8)

Boolean value

bool is a Boolean value, a Boolean value total is divided into two states

True is true

Flase is a fake

I want the computer to help us calculate the comparative size of two numbers

print(3>7)
结果:Flase
print(7>3)
结果: True

Entry

Qq login page or micro-channel will often need to enter an account or password, because a lot of the existence of such cases in the program will be the next to achieve their own input of a login function

s = input('请输入你喜欢的东西')

input is fixed format, meaning he is content inside the parentheses is input to the user to see the precautionary statements, let's let the user input received input and then assigned to the string s

1561985843248

python3的写法
name = input("请输入用户名")
print(name)

Note that the input program to get interactive content are strings

E.g

num = input ('请输入数字:')
print = (num+5)
结果:
请输入数字:6
Traceback(most recent call last):
    File"D/python_object/test.py",line 350,in<module>
    print(num+5)
TypeError:must be str,not int

Error, and it reminds us the wrong type, numbers and strings are not additive, but obviously we enter a number, in fact, we are looking at the digital input, but the input acquired are strings

This knowledge is used in which it?

If the job requires the user to enter some personal information such as account numbers, passwords, gender, hobbies, etc., that is, you need to pass information to the program which you enter, then you need to use the interactive user input.

note

在python2 中使用raw_input   获取的都是字符串
在python3 中使用input       获取的都是字符串

Process Control

Encounter choices in life, such as dice, guess the size, such as choosing which way to go home? Python program will encounter this situation, it would use the if statement.

This feature is in Python flow control statements if.

how to use? look down!

if 条件:#引号是将条件与结果分开。
    结果# 四个空格,或者一个Tab键,这个是告诉程序满足这个条件的结果。切记空格和Tab键不能混合使用

Analyzing conditions

age = input("输入年龄:")
if int(age) >=18:
    print("成年了,能干成年人的事了")

if else a second election

age = input('请输入要比较的数字:')
if int(num) >=22:
    print('可以扯证了')
elif int(num) >=18:
    print('成年了,可以做一些成年的事了')
elif int(num) <18:
    print('还是小屁孩')

Like multiple choice written more than cooperation, it is to determine which branch as long as there is a set up, the rest are not executing

Multiple options Radio (mandatory) if elif else

num = input('请输入要比较的数字')
if num >60:
    print("大了")
elif num <60:
    print("小了")
else:
    print("猜对了")

Nesting

name = input('请输入名字:')
if name == 'meet':
    age = input('请输入年龄:')
    if int(age) == 18:
        print('输入全部正确')
    else:
        print('年龄输入错误!')
else:
    print('名字输入错误')

Such wording is very popular, so that you can clearly understand the user to enter the name and age which is wrong, and also to be a judge to determine if the name is correct password and then perform.

Guess you like

Origin www.cnblogs.com/sjf981012-/p/11116850.html