In Programming, data types is an important concept
Variables can store data of different types, and different types can do different things
Python has the following data types built-in by default, in these categories:
Text Type: str
Numeric Types: int, float, complex
Sequence Types: list, tuple, range
Mapping Types: set, frozenset
Boolean Type: bool
Binary Types: Bytes, bytearray, memoryview
Data Variables:
Variable 可以看成一个container
string: str---可以看成一个text
numeric:
int---number
Numbers: There are three numeric types in Python:
Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length
Float: Float, or floating point number is a number, positive or negative, containing one or more decimals
Complex: Complex numbers are written with a jas the imaginary part
Type Conversion: You can convert from one type to another with the int(), float()and complex() methods
Random Number: Python does not have a random()function to make a random number, bu Python has a built-in module called random that can be used to make random numbers
Casting:
Specify a Variable Type
There may be times when you want to specify a type on to a variable. This can be done with casting. Python is an object-orientated language, and as such it uses classes to define data types, including its primitive types.
Casting in Python is there done using constructor functions
int()-Constructs an integer number. From an integer literal, a float literal(by rounding down to the previous whole number), or a string literal( providing the string represents a whole number)
float()-Constructs a float number from an integer float literal or a string literal( providing the string represents a float or an integer)
str()- Constructs a string from a wide variety of data types, including strings, integer literals and float literals.
Boolean:
Boolean Values In Programming you often need to know if an expression is True or False.
You can evaluate any expression in Python, and get one of two answers, True or False.
When you compare two values, the expression is evaluated, and Python returns the Boolean answer.
The only way you get False is there is no value in the context.
Operators:
Operators are used to perform operations on variables values Python divides the operators in the following groups
What you need to learn python:
Python has:
technical advantages
open source--free
general purpose: data analysis and web programming(Django)
high-level: it employs syntax a lot closer to human logic
practical application(应用领域广): finance, economics...
Python basics
linux 命令
Syntax
Indentation: block of code
Commnets:
Data Types:
In Programming, data types is an important concept
Variables can store data of different types, and different types can do different things
Python has the following data types built-in by default, in these categories:
Data Variables:
Casting:
Boolean:
Operators:
Operators are used to perform operations on variables values Python divides the operators in the following groups
Arithmetic Operator
Assignment Operator
Comparison Operators
Identity Operator
Membership Operators
Bitwise Operators