Introduction to common shortcut keys and data types for basic learning of python introductory

foreword

As one of the most used programming languages ​​today, the Python language has a wide application prospect and is easier to use than other programming languages. Here, the author summarizes the learning experience and notes sharing of the python language from shallow to deep. I don’t talk redundant nonsense, but only record the most useful knowledge points. I hope to learn and communicate with all programmers, discuss problems together, and make progress together. Any errors or omissions or any inappropriateness are welcome to communicate and discuss with the author. In the future, we will continue to improve and add new content. This is the beginning of the article and we will continue to make progress in the future.
The most commonly used programming software for learning the Python language is pycharm. Needless to say, it has powerful functions and high efficiency. Programs save time and effort, making our work more elegant and efficient.
The author first introduces a few very commonly used shortcut key usage methods.

Common shortcut key collocation and function

ctrl+alt+s : open the software settings
ctrl+d : copy the current line of code
shift+alt+up\down keys : move the current line of code up or down
ctrl+shift+f10 : run the current code file
ctrl+f6 : rename File
ctrl+a : select all
ctrl+c\v\x : copy, paste, cut
ctl+f : search

Two Annotation Methods

single line comment#
multiline comment‘’’ ‘’’

type of data

Students who have studied other programming languages ​​know that programming languages ​​have data types, and python is no exception. Python data types are mainly divided into six categories:Number (number), string (string), tuple (tuple), list (list), dictionary (dictionary), set (set). Among them, these data are divided into variable types and immutable types. Immutable means that there is no addition, deletion, and modification operations, and it is a static number type, such as: numbers (numbers), strings (strings), and tuples (tuples); A variable type is a dynamic data type that supports addition, deletion, and modification operations. Number types can also be subdivided into integer type int, floating-point type float, complex number complex, and Boolean type bool.
Here, I will briefly introduce the three most common data types, which are most used as basic learning.
string : character string, with quotation marks, for example: "Xiaobai"
int integer, for example: 1
float : floating point type, for example: 1.2

view data type

There are so many data types, when we don't know what type the data is, is there any way for the program to tell us by itself? It's very simple, I can check the type of data by myself,The syntax is also simple: type()
Let me give you a few examples:
① You can assign a value to a variable through type(), and then output the variable to view the type:
a="小白"
a_type=type(a) #查看a的类型并赋值给a_type
print(a_type) #输出a_type查看a_type的内容
Running results:
insert image description here

②Simple, you can directly print out the type of data you want to view:
print(type("你好"))
running results:
insert image description here

In addition, I would like to add a note: variables have no type.

data type conversion

After learning to view data types, how to convert between data types? First look at the conversion syntax:
int(x) : convert x to an integer
float(x) : convert x to a floating point number
str(x) : convert the object x to a string
There is also a note here: any type convertible string. However, strings may not necessarily be converted to other types, and after data type conversion, data values ​​may be affected. Here are a few examples of data type conversion:

①Number to string
str(1)

② String to number
int("11")
Note here: the content of the string must be all numbers. If it is not all numbers, the conversion cannot be successful, and an error will be reported when running.
③ String to floating point number
float("11.11")

④Integer to floating point number
float(11)
After conversion, the result becomes 11.0
⑤Floating point number to integer
int(11.11)
Note: The conversion of floating point number to integer will lose precision, and the result after conversion is 11.

Guess you like

Origin blog.csdn.net/weixin_44996886/article/details/132263071