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

Python Programming unit 1

The document provides an overview of Python programming, detailing its origin, features, and program structure. It emphasizes Python's simplicity, readability, and versatility, making it suitable for various applications, particularly in data science and machine learning. Additionally, it covers identifiers, reserved words, and the IDLE Python interpreter, highlighting its user-friendly features for beginners.

Uploaded by

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

Python Programming unit 1

The document provides an overview of Python programming, detailing its origin, features, and program structure. It emphasizes Python's simplicity, readability, and versatility, making it suitable for various applications, particularly in data science and machine learning. Additionally, it covers identifiers, reserved words, and the IDLE Python interpreter, highlighting its user-friendly features for beginners.

Uploaded by

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

PYTHON

PROGRAMMING
Unit 1
Contents
• Origin
• Need of Python Programming
• Features
• Program Structure
• Identifiers
• Reserved Words
• IDLE-Python Interpreter
Origin
• created by Guido Van Rossum
• released on February 20, 1991
• maintained by Python Software Foundation, a non-profit membership organization
• The name python was inspired by Monty Python’s Flying Circus , which was a
very famous show on BBC back in the 1970s and Van Rossum happened to be a big
fan of that show.
• Python emphasizes code readability and its syntax allows programmers to write
codes in fewer lines compared to other languages
Need of Python Programming
• When compared to any other high-level programming languages such as C++ and
Java, it requires the programmer to develop lesser codes. Python is designed to be
simple and easy to read and write.
• Python can be utilized for a wide range of applications such as scripting,
developing, and testing. Because of its elegance and simplicity, Dropbox, Google,
Quora, Hewlett-Packard, and so many other top tech companies have already
implemented Python.
• With the growing trend of Data Science and Machine Learning, Python has equally
become one of the most important scripting languages in the 21st century, because
of its wide range of libraries and frameworks.
Features
• Object-Oriented: Python was created with an Object-oriented programming
approach which helps in writing clean and clear code. Object-oriented programming
can be achieved through Python Class.
• Use of Interpreter: Python codes are interpreted line by line at a time using the
Interpreter. This also helps in debugging.
• Free and Open-source: This is a free and open-source programming language so
everyone can use it.
• Simple: It is simple to use as it is just like an English sentence resulting in fast
coding and execution.
Features
• Can be Integrated: It can be integrated with other programming languages like C,
C+, Java, and many more. This will also teach you most of the programming
concepts.
• Cross-platform: Python is a cross-platform programming language which means it
allows you to use it on any platform like Windows, Linux, Mac, Unix, etc.
• Large library: Python’s ecosystem is large and growing, with a wide range of open-
source packages and libraries. There are over 137,000 Python libraries.
• Elegant Syntax: Python has a simple syntax that improves readability and lowers
code maintenance costs which makes code elegant and straightforward.
Program Structure
• Python is a high-level, interpreted programming language that is easy to learn and
use. It has a simple and easy-to-understand syntax that emphasizes readability and
reduces the cost of program maintenance. The basic structure of a Python program
consists of the following components:
• Comments: Comments are used to explain the purpose of the code or to make notes for
other programmers. They start with a ‘#’ symbol and are ignored by the interpreter.
• Import Statements: Import statements are used to import modules or libraries into the
program. These modules contain predefined functions that can be used to accomplish
tasks.
• Variables: Variables are used to store data in memory for later use. In Python, variables do
not need to be declared with a specific type.
• Data Types: Python supports several built-in data types including integers, floats, strings,
Booleans, and lists.
Program Structure
• Operators: Operators are used to perform operations on variables and data. Python
supports arithmetic, comparison, and logical operators.
• Control Structures: Control structures are used to control the flow of a program. Python
supports if-else statements, for loops, and while loops.
• Functions: Functions are used to group a set of related statements together and give them a
name. They can be reused throughout a program.
• Classes: Classes are used to define objects that have specific attributes and methods. They
are used to create more complex data structures and encapsulate code.
• Exceptions: Exceptions are used to handle errors that may occur during the execution of a
program.

• Overall, the basic structure of a Python program consists of these components


working together to accomplish a specific task or solve a particular problem.
Identifiers
• Python Identifier is the name we give to identify a variable, function, class, module
or other object. That means whenever we want to give an entity a name, that’s called
identifier.
• Sometimes variable and identifier are often misunderstood as same but they are not.
• A variable, as the name indicates is something whose value is changeable over time.
In fact a variable is a memory location where a value can be stored. Later we can
retrieve the value to use. But for doing it we need to give a nickname to that
memory location so that we can refer to it. That’s identifier, the nickname.
Rules for writing Identifiers
• There are some rules for writing Identifiers. But first you must know Python is case
sensitive. That means Name and name are two different identifiers in Python. Here
are some rules for writing Identifiers in python.
• Identifiers can be combination of uppercase and lowercase letters, digits or an
underscore(_). So myVariable, variable_1, variable_for_print all are valid python
identifiers.
• An Identifier can not start with digit. So while variable1 is valid, 1variable is not valid.
• We can’t use special symbols like !,#,@,%,$ etc in our Identifier.
• Identifier can be of any length.
Rules for writing Identifiers
• Though these are hard rules for writing identifiers, also there are some naming
conventions which are not mandatory but rather good practices to follow.
• Class names start with an uppercase letter. All other identifiers start with a lowercase
letter.
• Starting an identifier with a single leading underscore indicates the identifier is private.
• If the identifier starts and ends with two underscores, than means the identifier is
language-defined special name.
• While c = 10 is valid, writing count = 10 would make more sense and it would be easier to
figure out what it does even when you look at your code after a long time.
• Multiple words can be separated using an underscore, for example this_is_a_variable.
Reserved Words or Keywords
• Keywords are predefined, reserved words used in Python programming that have
special meanings to the compiler.
• We cannot use a keyword as a variable name, function name, or any other identifier.
They are used to define the syntax and structure of the Python language.
IDLE- Python Interpreter
• IDLE is Python’s Integrated Development and Learning Environment.
• IDLE has the following features:
• coded in 100% pure Python, using the tkinter GUI toolkit
• cross-platform: works mostly the same on Windows, Unix, and macOS
• Python shell window (interactive interpreter) with colorizing of code input, output, and
error messages
• multi-window text editor with multiple undo, Python colorizing, smart indent, call tips,
auto completion, and other features
• search within any window, replace within editor windows, and search through multiple
files (grep)
• debugger with persistent breakpoints, stepping, and viewing of global and local
namespaces
• configuration, browsers, and other dialogs
IDLE- Python Interpreter
• It provides a simple and convenient way to write, edit, and execute Python code.
• Python IDLE offers features like syntax highlighting, code autocompletion, and code
indentation to enhance the coding experience.
• It includes an interactive shell, known as the Python Shell, where you can execute Python
code line by line and see the immediate results.
• Python IDLE allows you to create, save, and open Python scripts (.py files) for larger
projects.
• It also provides debugging capabilities to help identify and fix errors in your code.
• Python IDLE is beginner-friendly and widely used for learning and experimenting with
Python programming.
• While it is a useful tool for beginners, more advanced developers may prefer other IDEs
with additional features and customization options.

You might also like