当前位置:网站首页>Day2- syntax basis and variables

Day2- syntax basis and variables

2022-06-26 05:47:00 m0_ sixty-seven million thirty-six thousand three hundred and f

Summary of learning

The output function is to output the data in the program to the console
Input function : The program obtains data from the console

1.input function ( adopt input The result of the input data is a string , Cannot be applied to operations , To convert )

Variable = input( Enter the prompt message ) - Prompt the user to enter content , And save the input to the variable

age = input(' Please enter your age :')
print(age)

# Prompt the user for name, age and phone number

name = input(' Please enter your name :')
number = input(' Please enter your phone number :')
print(name, number)
print(' full name :',name, ' Telephone :', number)

2. Output function

print Is to display the data in the program on the console ( Print ) come out , All the contents displayed on the console must be print Printed content

1) Basic usage

a. One print Print a data

b. One print Print multiple data :print( data 1, data 2, data 3,…)

print(10, 20, 3,)
print(type(10.3), 10 + 2, type(' Hello '))
number = 11233
print(number)

2) Advanced usage

By default, a print The printed content occupies one line

a. customized end:print( data 1, data 2, end=’’)

Printing principle : Program designation print During operation , Will print the data first , And then print it end Value (end The default is line feed )

print(12, 15, end=' ')
print(11)
print(12)

If you want a blank line, enter an empty print()

print(11,end=';')
print(1)
print()
print(3)

b. customized sep

customized sep It is used to control when printing data at the same time , How data is separated from data , Default is space

print(1, 2, 3, sep=',')
print(1, 2, 3, sep=';')
print(1, 2, 3, sep='\n')    # \n  It's line changing 

print(1, 3, 2, sep=',', end=';')
print(1, 3, 2, end=',', sep=';')

3. notes

1) Single-line comments

ctr +/ Automatic generation

2) Multiline comment

Put the content between double quotation marks or single quotation marks in three English States

3) The function of annotation

a. Annotate the code with , Improve the readability of the code

b. Cancel code function

4. Lines and indents

1) That's ok

python One line of code , You can leave a semicolon at the end of a line

print('hello')
print(' Hello ')

If you have to display multiple statements on one line , Semicolons must be used between statements

print('hello');print(' Hello ')

2) Indent - The space before a statement is called indentation

A statement cannot be preceded by a space

5. Identifiers and keywords

1) identifier - Naming requirements

python Identifier requirements : By letter 、 Numbers or underscores , And numbers don't start ( There can be no symbols other than these three )

a = 100
a1 = 100
a1_ = 100

2) keyword - python Some identifiers with special functions or special meanings in

Print all keywords

from keyword import kwlist
print(kwlist)

6. Common data and data types
1) Digital data : Data used to represent the size of a numeric value , For example, age 、 height 、 distance , amount of money
The method of representing digital data in a program : The same way that numbers are represented in Mathematics , Support scientific counting
The type corresponding to the number : Digital data is divided into integer types (int) And floating point (float) Two kinds of
2) Text data : It is used to represent the data corresponding to text information , for example : full name , Address , School name , Phone number , Zip code , Id card number
Representation : Text data must be enclosed in double or single quotation marks
type : character string (str, Abbreviations of words )
3) Boolean data : Only True and False Two values ,True It means true , To affirm ,False It means false , Denying
(True and false Is the key word )
Representation : direct writing True perhaps False, Don't add any characters
type : Boolean ( English translation ,bool)
4) Null value :None( It means nothing )
keyword :None
type :None Type

7. operation

1) Get data type :type( data ) - Gets the type of the specified data

type(3.2)
print(type(3.2))
print(type(True))
print(type(' Hello '))

character string ( Text data )

2) Type conversion : Type name in parentheses - Converts the specified data to the specified type

 take 10.9 Convert to integer 

int(10.9)
print(int(10.9))

Homework

choice question

  1. B
  2. C
  3. B
  4. C
  5. D

Completion

  1. #; “”“ ”“”
  2. 10;20
  3. .py
  4. integer
  5. Single quotation marks ; Double quotes
  6. two ;Ture、False
  7. type

Programming questions

x = str(input(' Please enter a user name :'))
y = int(input(' Please input a password :'))
print(' user name :', 'x', ' password :', y)
x, y, z = 1, 2, 3
print(x, y, z, sep='=')

Short answer

  1. The variable name is named by the programmer ; Is an identifier. , It can't be a keyword ; When you choose a name, you should see the name and know the meaning , Do not use system function names 、 Class name and module name , The letters are all lowercase , Multiple words are separated by underscores .

  2. 1) Easy to learn

2) High development efficiency

3) Explanatory language , Platform portability

4) It supports both mainstream programming paradigms

5) The degree of standardization , High readability

  1. 1) Data analysis

    2) Artificial intelligence

    3) Quantum trading

    4) Network data collection

    5) automated testing

    6) machine learning

原网站

版权声明
本文为[m0_ sixty-seven million thirty-six thousand three hundred and f]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202180505254196.html