0% found this document useful (0 votes)
62 views

Python Chapter 1 Notes by Ur Engineering Friend

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views

Python Chapter 1 Notes by Ur Engineering Friend

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Python Lecture #1

Notes

1. Introduction to Python Programming Language

What is Python :

Python is a popular programming language. It was created by Guido van Rossum, and
released in 1991.

Python is an interpreted, high-level and general-purpose programming language. Python's


design philosophy emphasizes code readability with its notable use of significant whitespace.
Its language constructs and object-oriented approach aim to Help programmers write clear,
logical code for small and large-scale projects. Python is dynamically typed and garbage-
collected.

It supports multiple programming paradigms,


including structured (particularly, procedural), object-oriented, and functional programming.
Python is often described as a "batteries included" language due to its
comprehensive standard library. Python was created in the late 1980s, and first released in
1991, by Guido van Rossum as a successor to the ABC programming language.

It is used for:

 web development (server-side),


 software development,
 mathematics,
 system scripting.

What can Python do?

 Python can be used on a server to create web applications.

MSBTE NEXT ICON COURSE YOUTUBE – UR ENGINEERING FRIEND


 Python can be used alongside software to create workflows.
 Python can connect to database systems. It can also read and modify files.
 Python can be used to handle big data and perform complex mathematics.
 Python can be used for rapid prototyping, or for production-ready software
development.

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.

2. Features of Python Programming Language

There are many features in Python:-

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.

2. Free and Open Source:

MSBTE NEXT ICON COURSE YOUTUBE – UR ENGINEERING FRIEND


Python language is freely available at the official website and you can download it.
Since it is open-source, this means that source code is also available to the public.

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.

4. GUI Programming Support:

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:

Python is a high-level language. When we write programs in python, we do not need to


remember the system architecture, nor do we need to manage the memory.

6.Python is Interactive :

You can actually sit at a Python prompt and interact with the interpreter directly to write your
programs.

7. Python is Portable language:

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.

8. Python is Integrated language:

MSBTE NEXT ICON COURSE YOUTUBE – UR ENGINEERING FRIEND


Python is also an Integrated language because we can easily integrated python with other
languages like c, c++, etc.

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.

10. Large Standard Library

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.

11. Dynamically Typed Language:

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.

3. Building Blocks of Python Programming Language

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.

MSBTE NEXT ICON COURSE YOUTUBE – UR ENGINEERING FRIEND


 Identifiers are case sensitive (count and Count are different variables).
 Reserved words (keywords) cannot be used as identifiers.
 an identifier can be any length.

Example of valid Identifiers.

 ab10c: contains only letters and numbers


 abc_DE: contains all the valid characters
 _: surprisingly but Yes, underscore is a valid identifier
 _abc: identifier can start with an underscore.

Example of invalid identifiers.

 99: identifier can’t be only digits


 9abc: identifier can’t start with number
 x+y: the only special character allowed is an underscore
 for: it’s a reserved keyword

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:

Keywords in Python programming language

False await else import pass

None break except in raise

True class finally is return

and continue for lambda try

as def from nonlocal while

assert del global not with

async elif if or yield

MSBTE NEXT ICON COURSE YOUTUBE – UR ENGINEERING FRIEND


3.Python Indentation

 Indentation refers to the spaces at the beginning of a code line.

 Where in other programming languages the indentation in code is for readability only,
the indentation in Python is very important.

 Python uses indentation to indicate a block of code.

Example:

# Python program showing


# indentation

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

MSBTE NEXT ICON COURSE YOUTUBE – UR ENGINEERING FRIEND


 Comments can be used to explain Python code.

 Comments can be used to make the code more readable.

 Comments can be used to prevent execution when testing code.

4. Datatypes of Python Programming Language

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

MSBTE NEXT ICON COURSE YOUTUBE – UR ENGINEERING FRIEND


followed by a positive or negative integer may be appended to specify scientific
notation. For example f=1.5
 Complex Numbers – Complex number is represented by complex class. It is specified
as (real part) + (imaginary part)j. For example – 2+3j.

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.

5.Dictionary:-Python dictionary is an unordered collection of items. Each item of a


dictionary has a key/value pair.Each key is separated from its value by a colon (:), the items
are separated by commas, and the whole thing is enclosed in curly braces. An empty
dictionary without any items is written with just two curly braces, like this: {}.Keys are
unique within a dictionary while values may not be. The values of a dictionary can be of any
type, but the keys must be of an immutable data type such as strings, numbers, or tuples.

#Creating Dictionary

MSBTE NEXT ICON COURSE YOUTUBE – UR ENGINEERING FRIEND


# empty dictionary
my_dict = {}

# dictionary with integer keys


my_dict = {1: 'apple', 2: 'ball'}

MSBTE NEXT ICON COURSE YOUTUBE – UR ENGINEERING FRIEND

You might also like