tags: j computer secondary python
Without further ado, let ’s first look at the requirements in the exam outline
In the first section, let ’s analyze the first and second parts of the exam.
One:
The format framework of the program:
The Python program format framework is not much different from the C language we learned earlier. Here we use a few lines of code to illustrate the problem.
There is no need to add ";" after each sentence is written. This is more convenient. The reserved words will be displayed in different colors. The input and output character type data should be added''or""In general, it is quite simple. Of course, the exam will not take this.
Indent:
because they are indented. Python makes code more readable by using indentation; in short, it requires you to use indentation to make your code neat and structured. In longer Python programs, you will see code blocks with varying degrees of shrinkage, which gives you a general understanding of the organization of the program. When you start writing code that must be indented correctly, you need to pay attention to some common indentation errors. For example, sometimes, programmers indent code blocks that do not need to be indented, but forget to indent code blocks that must be indented. By looking at such error examples, it is helpful for you to avoid them later and fix them when they appear in the program. Increasing the indentation indicates the beginning of the statement block, while decreasing the indentation indicates the end of the statement block. Indentation becomes part of the grammar. Use a few lines of code to illustrate the problem
When writing print (i) to output, there is an indentation of the “Tab” key in front of it, occupying four spaces.
Note:
The single-line comment in Python is very simple. Just add "#" at the top of a line. Multi-line comments, starting and ending with "", will not be demonstrated here.
Variable:
Variables are placeholders used to save and represent data in a program.
Name:
The naming of variables in Python is the same as the rules to be followed in C language. Variable names can consist of numbers, letters, and underscores, but numbers cannot start with a case-sensitive character. Here are a few examples to illustrate the problem.
Reserved words:
Reserved words are keywords in C language. There are the following keywords in python:
[‘False’, ‘None’, ‘True’, ‘and’, ‘as’, ‘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’]
References:
Data type:
Assignment statement:
A very simple sentence, for example.name=2, This is a very simple assignment statement.
Quote:
There is no variable in Python, the variable we define is just a label, it is just a reference to the object. Numbers are objects, lists are objects, and so on. For example, a = 2, essentially 2 is an object, and a is a reference to object 2.
2. Basic input and output functions
The print () function is the most basic function. Before python3.x, the print function output did not need to bring (), now you need to put parentheses. No quotes are needed to output numbers and characters, and the strings need to be quoted.
input () input function, it should be noted that whether you input characters or numbers, they will be converted into character types.
The eval () function: The eval (str) function is very powerful. The official interpretation is: evaluate the string str as a valid expression and return the calculation result. Therefore, combining math as a calculator is very useful.
eval () transferred from:
Two:
The first basic data type is in the icon above, we will not discuss it, it is worth mentioning that floating-point numbers in Python do not distinguish between single precision and double precision. The complex number can be expressed as a = 1 + 2j or complex (a, b).
2. Number type operation:
The picture comes from:
Numerical operation function: There is a special function library "math" in Python, which can perform various operations on numerical values. For details, you can look at the math documentation:https://www.rddoc.com/doc/Python/3.6.0/zh/library/math/#constants
3. Type and format of character string:
About indexing and slicing, we use code to demonstrate:
explained as follows: "hello" has a total of five characters, the first one is 'h', the fifth is 'o', but in the index, the first character 'h' Starting from 0, the fourth one is 'o'. When slicing, name [0: 4] represents the acquisition from the 0th to the third, excluding the fourth. In other words, name [0] = <str <name [4].
Basic format () formatting method:
The first function of format () is to fill
Examples:
print("{0} {1}".format("hello","world"))
hello world
The output is "hello world", meaning that the 0 and 1 in the format function are filled to the front.
The second function is output formatting:
Examples:
print("{:.2f}".format(3.14159))
3.14
4: String type operation
Processing function: `# Split str into list
str.split()
str.isdecimal () returns True if all
str.isalpha () returns True if all
str.count(str1)
str.replace(old,new)
str.strip()
str.title()
str.lstrip(rstrip).()`
5: Type judgment
This is obvious.
Type conversion:
Everyone is good, I haven't met with you for a long time! ! I have been busy with my own things, so I haven't updated it for a long time. I am sorry to say to everyone. Recently, Xu boldly will contin...
In SQL Server 2008, there is a product table (product number, trade name, purchase price) in a database, The product number is the main code, the sales list (product number, sales time, sales quantity...
There is a product list (product number, trade name, single price) and sales table (sales document number, product number, sales time, sales quantity, sales price). Among them, the product number repr...
Python123 recommended by the Ministry of Education is the only pro forma platform (click to jump) If you want to test computer grade examination "secondary Python programming language," then...
Youth Computer Rank Exam (Ycre), URL:https://www.nycre.cn/ 【topic】Kabake 【Problem Description】 anyoneFour digitsAs long as the numbers on each of them areNot all the sameThere is such a law: 1 will ma...
National Computer Rank Examination Two CLanguage exam review materials (written) Lesson C language programming foundation This lesson main points: 1. knowledge: C program basis l C language is a struc...
Yesterday I checked the results. Although 73 points are not high, I am very happy after all. After all, I have tested the C language once, and I was crying to death when I checked the 56 points last t...
The 10th set: In a given program, the function of function is: whether the matrix of n × n (specified N is odd) referred to in the parameter A is "illusion". If the function returns va...
The 12th set: In a given procedure, the function of function FUN is to reverse the one-way linked list without header nodes. That is, if the original list is in turn from the head to the tailpoint dat...
Years 03: The program has stored students' student scholars, names and 3 lessons. All student data is output to the file in binary. Function FUN function is to rewrite the data of the last student in ...