Python Chapter 1 Notes by Ur Engineering Friend
Python Chapter 1 Notes by Ur Engineering Friend
Notes
What is Python :
Python is a popular programming language. It was created by Guido van Rossum, and
released in 1991.
It is used for:
Why Python?
Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc).
Python has a simple syntax similar to the English language.
Python has syntax that allows developers to write programs with fewer lines than
some other programming languages.
Python runs on an interpreter system, meaning that code can be executed as soon as it
is written. This means that prototyping can be very quick.
Python can be treated in a procedural way, an object-oriented way or a functional
way.
1. Easy to use:
Python is a high-level programming language. Python is very easy to learn the language as
compared to other languages like C, C#, JavaScript, Java, etc. It is very easy to code in
python language and anybody can learn python basics in a few hours or days. It is also a
developer-friendly language.
3. Object-Oriented Language:
One of the key features of python is Object-Oriented programming. Python supports object-
oriented language and concepts of classes, objects encapsulation, etc.
Graphical User interfaces can be made using a module such as PyQt5, PyQt4, wxPython, or Tk
in python. PyQt5 is the most popular option for creating graphical apps with Python.
5. High-Level Language:
6.Python is Interactive :
You can actually sit at a Python prompt and interact with the interpreter directly to write your
programs.
Python language is also a portable language. For example, if we have python code for windows
and if we want to run this code on other platforms such as Linux, UNIX, and Mac then we do
not need to change it, we can run this code on any platform.
9. Interpreted Language:
Python is an Interpreted Language because Python code is executed line by line at a time. like
other languages C, C++, Java, etc. there is no need to compile python code this makes it easier
to debug our code. The source code of python is converted into an immediate form
called bytecode.
Python has a large standard library which provides a rich set of module and functions so you do
not have to write your own code for every single thing. There are many libraries present in
python for such as regular expressions, unit-testing, web browsers, etc.
Python is a dynamically-typed language. That means the type (for example- int, double, long,
etc.) for a variable is decided at run time not in advance because of this feature we don’t need to
specify the type of variable.
1.Identifiers
Identifiers are the names for things (variables, functions, etc) in the language. Some
identifiers are built-in, and others can be created by the programmer.
User-defined identifiers can consist of letters, digits, underscores, and the dollar-sign $.
Must start with a non-digit.
2. Keywords
Python has a set of keywords that are reserved words that cannot be used as variable names,
function names, or any other identifiers:
Where in other programming languages the indentation in code is for readability only,
the indentation in Python is very important.
Example:
site = 'Pyt'
if site == 'Pyt':
print('Logging on to Python...')
else:
print('retype the URL.')
print('All set !')
Output:
Logging on to Python…
All set !
4. Variables
Variables are containers for storing data values.
A variable is a named location used to store data in the memory. It is helpful to think
of variables as a container that holds data that can be changed later in the program.
Example:
x = 5
y = "John"
print(x)
print(y)
Output:
5
John
5. Comments
1. Numeric:-In Python, numeric data type represent the data which has numeric value.
Numeric value can be integer, floating number or even complex numbers. These values are
defined as int, float and complex class in Python.
Integers – This value is represented by int class. It contains positive or negative whole
numbers (without fraction or decimal). In Python there is no limit to how long an
integer value can be. For example i=15
Float – This value is represented by float class. It is a real number with floating point
representation. It is specified by a decimal point. Optionally, the character e or E
2.String:-In Python, Strings are arrays of bytes representing Unicode characters. A string is a
collection of one or more characters put in a single quote, double-quote or triple quote. In
python there is no character data type, a character is a string of length one. It is represented
by str class.
my_string = 'Hello'
print(my_string)
3. List:-Lists are just like the arrays, declared in other languages which is a ordered
collection of data. It is very flexible as the items in a list do not need to be of the same type.
Lists in Python can be created by just placing the sequence inside the square brackets[].
4.Tuple:-Tuples are used to store multiple items in a single variable.Tuple is one of 4 built-
in data types in Python used to store collections of data, the other 3 are List, Set,
And Dictionary, all with different qualities and usage.A tuple is a collection which is ordered
and unchangeable.Tuples are written with round brackets.
#Creating Dictionary