Lesson.-Python-Programming-Language
Lesson.-Python-Programming-Language
Lesson.-Python-Programming-Language
What is Python?
Features of Python
Example:
Python Install
python --version
The way to run a python file is like this on the command line:
Example
helloworld.py
print ("Hello, World!")
Hello, World!
Python Syntax
Python Indentation
Example:
Example:
Syntax Error
Example
You have to use the same number of spaces in the same block of
code, otherwise Python will give you an error:
Python Comments
Creating a Comment
Variables
Creating Variables
Example
Variable Names
A variable can have a short name (like x and y) or a more
descriptive name (age, carname, total_volume).
Python Keywords
Python has a set of keywords that are reserved words that cannot be used as
variable names, function names, or any other identifiers:
Keyword Description
as To create an alias
assert For debugging
or A logical operator
Example:
Output Variables
The Python print() function is often used to output variables.
Example
Example
Notice the space character after "Python " and "is ", without
them the result would be "Pythonisawesome".
2
3
Example
Example
Variables can store data of different types, and different types can
do different things.
Example
1. String
2. Integer
3. Float
4. Complex
5. List
6. Tuple
7. Range
8. Dict
9. Set
10.Frozenset
11.Boolean
12.Byte
13.Bytearray
14.memoryview
15. NoneType
String
A string is a data type that represents a sequence of
characters, words, or symbols. It is a sequence of characters
and can contain letters, numbers, symbols and even spaces. It
must be enclosed in quotation marks (“ “).
Example:
Integer
Integer is a whole number, positive or negative, without a
decimal or fractional part. Integers are represented in a
computer as a group of binary digits, or bits, and are stored in
memory locations.
Float
A float is a data type that stores fractional numbers, or
floating-point numbers, which are numbers with a decimal point.
Floats are used when more precision is needed than integers,
which are numbers without a decimal point.
Complex
Complex refers to the interactions between the various elements
of software, and how complicated it is for a developer to
understand.
Complexity is a measure of how complicated a piece of code is,
and how difficult it is to understand.
List
A list is a fundamental data structure that organizes and
manipulates data by storing related items in a specific order.
Tuple
A tuple is a finite, ordered sequence of elements that can be of
different data types.
Tuples are used to store multiple values in a single object, and
are often used to return multiple values from a method.
Range
Range refer to one of three things: The possible values that may
be stored in a variable.
The upper and lower bounds of an array.
Array is a data structure that stores a fixed number of
variables of the same type.
An alternative to iterator.
Iterator is an object that allows access to each item in a
collection in order.
dict
dict is a built-in data type that stores data in key-value
pairs.
Set
Set is an abstract data type that can store unique values,
without any particular order. It is a computer implementation of
the mathematical concept of a finite set.
Frozenset
Bool (Boolean)
Try it
Bytes
bytearray
Memoryview
NoneType
References:
https://www.w3schools.com/python/