Variables and Identifiers-
A variable is a name that is associated
with a value. The assignment operator is used to assign values to
variables. An immutable value is a value that cannot be changed.
Num= 10
An identifier is a sequence of one or
more characters used to name a given program element. In
Python, an identifier may contain letters and
digits, but cannot begin with a digit. The special underscore character can
also be used.
Data Types
1. Integers
2. Booleans
3. Floating-Point Types
Integers
Python integers have unlimited range, subject
only to the available virtual memory. This means that it doesn't really matter
how big a number you want to store: as long as it can fit in your computer's
memory, Python will take care of it. Integer numbers can be positive, negative,
and 0 (zero). They support all the basic mathematical operations, as shown in
the following example:
>>> a =
12
>>> b =
3
Booleans
There are two built-in Boolean objects: True
and False. Like all other Python data types (whether built-in, library, or custom),
the bool data type can be called as a function—with no arguments it returns
False, with a bool argument it returns a copy of the argument, and with any
other argument it attempts to convert the given object to a bool. All the
built-in and standard library data types can be converted to produce a Boolean
value, and it is easy to provide Boolean conversions for custom data types.
Here are a couple of Boolean assignments and a couple of Boolean expressions:
>>> t = True
>>> f = False
>>> t and f
False
>>> t and True
True
Floating-Point Types
Python provides three kinds of floating-point
values: the built-in float and complex types, and the decimal. Decimal type
from the standard library. All three are immutable. Type float holds
double-precision floating-point numbers whose range depends on the C (or C# or
Java) compiler Python was built with; they have limited precision and cannot
reliably be compared for equality.
Numbers of type float are written with a
decimal point, or using exponential notation, for example, 0.0, 4., 5.7, -2.5,
-2e9, 8.9e-4.
No comments:
Post a Comment