In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "which operators does Python support". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Instructions and programs
The hardware system of a computer is usually composed of five components, including an arithmetic unit, a controller, a memory, an input device and an output device. Among them, the arithmetic unit and the controller put together is what we usually call the central processing unit, its function is to perform a variety of operations and control instructions and process data in computer software. What we usually call a program is actually a collection of instructions. our program is to organize a series of instructions together in some way, and then use these instructions to control the computer to do what we want it to do. Although the computer we use today is becoming more and more sophisticated and powerful, it still belongs to the "von Neumann structure" in essence. "von Neumann structure" has two key points, one is to separate the storage device from the central processing unit, and the other is to encode the data in a binary way. Binary is a counting method of "every two into one", which is not substantially different from the "every ten into one" counting method used by human beings. humans use the decimal system because they have ten fingers (because ten fingers are used up when they are counted, of course, there are exceptions, and the Mayans may have counted their toes because they have been barefoot for years. So they used the decimal counting method, under the guidance of which the Mayan calendar was different from the calendar we usually use, and according to the Mayan calendar, 2012 was the last year of the last so-called "solar period." and 2013 is the beginning of a new "solar period." Later, this incident was misinterpreted as the absurd claim that "2012 was the end of the world predicted by the Mayans." Today, we can boldly guess that the slow development of Mayan civilization is also related to the use of the decimal system. For computers, binary is the easiest to implement on physical devices (high voltage means 1, low voltage means 0), so all computers in the "von Neumann structure" use binary. Although we don't need every programmer to be able to work in binary thinking, it is necessary to understand binary and its conversion relationship with the decimal system in our lives, as well as the conversion relationship between binary and octal and hexadecimal. If you are not familiar with this, you can use Wikipedia or Baidu encyclopedia to popularize science.
Variables and types
In programming, a variable is a carrier for storing data. The variable in the computer is the actual data or a piece of memory space in which the data is stored in memory, and the value of the variable can be read and modified, which is the basis of all calculation and control. There are many types of data that the computer can process. In addition to numerical values, it can also deal with text, graphics, audio, video and other kinds of data, so different data need to define different storage types. There are many data types in Python, and they allow us to customize new data types (which we'll talk about later). Let's start with a few commonly used data types.
Integers: Python can handle integers of any size (there are two types of integers int and long in Python 2.x, but this distinction doesn't make much sense for Python, so there is only int for integers in Python 3.x), and supports binary (such as 0b100, converted to decimal is 4), octal (such as 0o100, converted to decimal is 64), decimal (100) and hexadecimal (0x100). The representation converted to decimal is 256).
Floating point: floating-point numbers, that is, decimals, are called floating-point numbers because the position of the decimal point of a floating-point number is variable when represented according to scientific notation. Floating-point numbers support scientific counting in addition to mathematical writing (e.g. 123.456).
String type: a string is any text enclosed in single or double quotes, such as' hello' and "hello. Strings also have original string representations, byte string representations, Unicode string representations, and can be written in the form of multiple lines (beginning with three single or three double quotes, ending with three single quotes or three double quotes).
Boolean: Boolean values are only available in True and False, either True or False. In Python, Boolean values can be directly represented by True and False (please note case), or can be calculated by Boolean operations (for example, 3
< 5会产生布尔值True,而2 == 1会产生布尔值False)。 复数型:形如3+5j,跟数学上的复数表示一样,唯一不同的是虚部的i换成了j。 变量命名 对于每个变量我们需要给它取一个名字,就如同我们每个人都有属于自己的响亮的名字一样。在Python中,变量命名需要遵循以下这些必须遵守硬性规则和强烈建议遵守的非硬性规则。 硬性规则: 变量名由字母(广义的Unicode字符,不包括特殊字符)、数字和下划线构成,数字不能开头。 大小写敏感(大写的a和小写的A是两个不同的变量)。 不要跟关键字(有特殊含义的单词,后面会讲到)和系统保留字(如函数、模块等的名字)冲突。 PEP 8要求: 用小写字母拼写,多个单词用下划线连接。 受保护的实例属性用单个下划线开头(后面会讲到)。 私有的实例属性用两个下划线开头(后面会讲到)。 当然,作为一个专业的程序员,给变量(事实上应该是所有的标识符)命名时做到见名知意也是非常重要的。 变量的使用 下面通过几个例子来说明变量的类型和变量使用。 """使用变量保存数据并进行算术运算Version: 0.1Author: 骆昊"""a = 321b = 123print(a + b)print(a - b)print(a * b)print(a / b)print(a // b)print(a % b)print(a ** b)"""使用input函数输入使用int()进行类型转换用占位符格式化输出的字符串Version: 0.1Author: 骆昊"""a = int(input('a = '))b = int(input('b = '))print('%d + %d = %d' % (a, b, a + b))print('%d - %d = %d' % (a, b, a - b))print('%d * %d = %d' % (a, b, a * b))print('%d / %d = %f' % (a, b, a / b))print('%d // %d = %d' % (a, b, a // b))print('%d %% %d = %d' % (a, b, a % b))print('%d ** %d = %d' % (a, b, a ** b))"""使用type()检查变量的类型Version: 0.1Author: 骆昊Date: 2018-02-27"""a = 100b = 12.345c = 1 + 5jd = 'hello, world'e = Trueprint(type(a))print(type(b))print(type(c))print(type(d))print(type(e)) 在对变量类型进行转换时可以使用Python的内置函数(准确的说下面列出的并不是真正意义上的函数,而是后面我们要讲到的创建对象的构造方法)。 int():将一个数值或字符串转换成整数,可以指定进制。 float():将一个字符串转换成浮点数。 str():将指定的对象转换成字符串形式,可以指定编码。 chr():将整数转换成该编码对应的字符串(一个字符)。 ord():将字符串(一个字符)转换成对应的编码(整数)。 运算符 Python支持多种运算符,下表大致按照优先级从高到低的顺序列出了所有的运算符,我们会陆续使用到它们。 运算符描述[] [:]下标,切片**指数~ + -按位取反, 正负号* / % //乘,除,模,整除+ -加,减>> =
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.