0% found this document useful (0 votes)
14 views8 pages

Introduction to Python Programming

Uploaded by

Mathan Sundar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views8 pages

Introduction to Python Programming

Uploaded by

Mathan Sundar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Language Introduction

➢ Python is a widely used general-purpose, high level programming language.


➢ It was created by Guido van Rossum in 1991 and further developed by the Python
Software Foundation.
➢ It was designed with an emphasis on code readability, and its syntax allows
programmers to express their concepts in fewer lines of code.
➢ Python is a programming language that lets you work quickly and integrate systems
more efficiently.
➢ Python ranks among the most popular and fastest-growing languages in the world.
➢ Python is a powerful, flexible, and easy-to-use language.
There are two major Python versions:
1. Python 2
2. Python 3.
Both are quite different.
Beginning with Python programming:
1) Finding an Interpreter:
Before we start Python programming, we need to have an interpreter to interpret and run our
programs. There are certain online interpreters that can be used to run Python programs without
installing an interpreter.
Windows: There are many interpreters available freely to run Python scripts like IDLE
(Integrated Development and Learning Environment) that comes bundled with the Python
software downloaded from [Link]
Linux: Python comes preinstalled with popular Linux distros such as Ubuntu and Fedora. To
check which version of Python you’re running, type “python” in the terminal emulator. The
interpreter should start and print the version number.
macOS: Generally, Python 2.7 comes bundled with macOS. You’ll have to manually install
Python 3 from [Link]
2) Writing our first program:
Just type in the following code after you start the interpreter.
# Script Begins
print("Hai")
# Scripts Ends
Output:
Hai
Let’s analyse the script line by line.
Line 1: [# Script Begins] In Python, comments begin with a #. This statement is ignored
by the interpreter and serves as documentation for our code.
Line 2: [print(“Hai”)] To print something on the console, print() function is used. This
function also adds a newline after our message is printed (unlike in C). Note that in Python
2, “print” is not a function but a keyword and therefore can be used without parentheses.
However, in Python 3, it is a function and must be invoked with parentheses.
Line 3: [# Script Ends] This is just another comment like in Line 1.
Advantages:
1. Presence of third-party modules
2. Extensive support libraries (NumPy for numerical calculations, Pandas for data
analytics etc)
3. Open source and community development
4. Versatile, Easy to read, learn and write
5. User-friendly data structures
6. High-level language
7. Dynamically typed language (No need to mention data type based on the value
assigned, it takes data type)
8. Object-oriented language
9. Portable and Interactive
10. Ideal for prototypes – provide more functionality with less coding
11. Highly Efficient (Python’s clean object-oriented design provides enhanced process
control, and the language is equipped with excellent text processing and integration
capabilities, as well as its own unit testing framework, which makes it more efficient.)
12. (IoT)Internet of Things Opportunities
13. Interpreted Language
14. Portable across Operating systems
Applications:
1. GUI based desktop applications
2. Graphic design, image processing applications, Games, and Scientific/ computational
Applications
3. Web frameworks and applications
4. Enterprise and Business applications
5. Operating Systems
6. Education
7. Database Access
8. Language Development
9. Prototyping
10. Software Development
Organizations using Python:
1. Google (Components of Google spider and Search Engine)
2. Yahoo (Maps)
3. YouTube
4. Mozilla
5. Dropbox
6. Microsoft
7. Cisco
8. Spotify
9. Quora

Python IDLE?
➢ Every Python installation comes with an Integrated Development and Learning
Environment, which you’ll see shortened to IDLE or even IDE.
➢ These are a class of applications that help you write code more efficiently.
➢ While there are many IDEs for you to choose from, Python IDLE is very bare-bones,
which makes it the perfect tool for a beginning programmer.
➢ Python IDLE comes included in Python installations on Windows and Mac.
➢ If you’re a Linux user, then you should be able to find and download Python IDLE
using your package manager.
➢ Once you’ve installed it, you can then use Python IDLE as an interactive interpreter or
as a file editor.
An Interactive Interpreter
➢ The best place to experiment with Python code is in the interactive interpreter,
otherwise known as a shell.
➢ The shell is a basic Read-Eval-Print Loop (REPL). It reads a Python statement, evaluates
the result of that statement, and then prints the result on the screen. Then, it loops back
to read the next statement.
➢ The Python shell is an excellent place to experiment with small code snippets.
➢ You can access it through the terminal or command line app on your machine.
➢ You can simplify your workflow with Python IDLE, which will immediately start a
Python shell when you open it.
A File Editor
➢ Every programmer needs to be able to edit and save text files.
➢ Python programs are files with the .py extension that contain lines of Python code.
➢ Python IDLE gives you the ability to create and edit these files with ease.
➢ Python IDLE also provides several useful features that you’ll see in professional IDEs,
like basic syntax highlighting, code completion, and auto-indentation.
➢ If you’re just beginning your Python programming journey, then Python IDLE is a great
alternative!
How to Use the Python IDLE Shell
➢ The shell is the default mode of operation for Python IDLE.
➢ When you click on the icon to open the program, the shell is the first thing that you see:

➢ This is a blank Python interpreter window.


➢ You can use it to start interacting with Python immediately. You can test it out with a
short line of code:

➢ Here, you used print () to output the string "Hello, from IDLE!" to your screen.
➢ This is the most basic way to interact with Python IDLE.
➢ You type in commands one at a time and Python responds with the result of each
command.
➢ Next, take a look at the menu bar. You’ll see a few options for using the shell:

➢ You can restart the shell from this menu.


➢ If you select that option, then you’ll clear the state of the shell.
➢ It will act as though you’ve started a fresh instance of Python IDLE.
➢ The shell will forget about everything from its previous state:

➢ In the image above, you first declare a variable, x = 5.


➢ When you call print(x), the shell shows the correct output, which is the number 5.
➢ However, when you restart the shell and try to call print(x) again, you can see that the
shell prints a traceback.
➢ This is an error message that says the variable x is not defined.
➢ The shell has forgotten about everything that came before it was restarted.
How to Work with Python Files
➢ Python IDLE offers a full-fledged file editor, which gives you the ability to write and
execute Python programs from within this program.
➢ The built-in file editor also includes several features, like code completion and automatic
indentation, that will speed up your coding workflow.
➢ First, let’s take a look at how to write and execute programs in Python IDLE.
Opening a File
➢ To start a new Python file, select File → New File from the menu bar.
➢ This will open a blank file in the editor, like this:

➢ From this window, you can write a brand-new Python file.


➢ You can also open an existing Python file by selecting File → Open… in the menu bar.
➢ This will bring up your operating system’s file browser.
➢ Then, you can find the Python file you want to open.
➢ If you’re interested in reading the source code for a Python module, then you can
select File → Path Browser.
➢ This will let you view the modules that Python IDLE can see.
Editing a File
➢ Once you’ve opened a file in Python IDLE, you can then make changes to it.
➢ When you’re ready to edit a file, you’ll see something like this:
➢ The contents of your file are displayed in the open window.
➢ The bar along the top of the window contains three pieces of important information:
1. The name of the file that you’re editing
2. The full path to the folder where you can find this file on your computer
3. The version of Python that IDLE is using
➢ In the image above, you’re editing the file [Link], which is located in
the Documents folder. The Python version is 3.7.1, which you can see in parentheses.
➢ There are also two numbers in the bottom right corner of the window:
1. Ln: shows the line number that your cursor is on.
2. Col: shows the column number that your cursor is on.
➢ It’s useful to see these numbers so that you can find errors more quickly.
➢ They also help you make sure that you’re staying within a certain line width.
➢ There are a few visual cues in this window that will help you remember to save your
work.
➢ If you look closely, then you’ll see that Python IDLE uses asterisks to let you know that
your file has unsaved changes:

➢ The file name shown in the top of the IDLE window is surrounded by asterisks.
➢ This means that there are unsaved changes in your editor.
➢ You can save these changes with your system’s standard keyboard shortcut, or you can
select File → Save from the menu bar.
➢ Make sure that you save your file with the .py extension so that syntax highlighting will
be enabled.
Executing a File
➢ When you want to execute a file that you’ve created in IDLE, you should first make sure
that it’s saved.
➢ Remember, you can see if your file is properly saved by looking for asterisks around the
filename at the top of the file editor window.
➢ Don’t worry if you forget, though! Python IDLE will remind you to save whenever you
attempt to execute an unsaved file.
➢ To execute a file in IDLE, simply press the F5 key on your keyboard. You can also
select Run → Run Module from the menu bar.
➢ Either option will restart the Python interpreter and then run the code that you’ve written
with a fresh interpreter.
➢ When your code is done executing, the interpreter will know everything about your code,
including any global variables, functions, and classes.
➢ This makes Python IDLE a great place to inspect your data if something goes wrong.
➢ If you ever need to interrupt the execution of your program, then you can press Ctrl+C in
the interpreter that’s running your code

Common questions

Powered by AI

Python is considered flexible and powerful due to its clean object-oriented design, which enhances process control and provides excellent text processing and integration capabilities. It has its own unit testing framework, making it efficient. Python supports the development of diverse applications, including GUI-based desktop applications, web frameworks, scientific applications, and IoT projects, due to its extensive support libraries and third-party modules .

Text processing is central to many Python applications, contributing to efficiency through powerful libraries that handle various formats and encoding seamlessly. Python's capabilities in text processing enable efficient manipulation and analysis of large datasets, improve search operations, and streamline data parsing. Libraries such as 're' for regex operations and 'StringIO' for in-memory text stream processing significantly enhance these capabilities .

The Python interpreter facilitates rapid prototyping through dynamic typing and an interpreted execution model that allows for quick iteration and testing of code. This is important for software development as it reduces the development cycle time, enabling developers to validate concepts and functionality quickly and effectively before full-scale implementation .

Dynamic typing in Python influences program design by allowing developers to write more flexible code without specifying data types. This reduces overhead and complexity in coding, facilitates code reuse, and aligns with Python’s philosophy of readability and simplicity. However, it requires developers to be cautious with type-related errors that are caught only at runtime, influencing testing practices and error handling strategies .

Python 2 and Python 3 differ primarily in their handling of core functions and syntax. For example, in Python 2, 'print' is a statement, whereas, in Python 3, 'print()' is a function, requiring parentheses. These differences affect practices by changing how certain basic tasks are implemented and can influence code compatibility and deployment environments, as many libraries have shifted support to Python 3 .

Python enhances operational capabilities by providing a scalable and efficient solution for developing components essential to organizational infrastructure. Google uses Python in components of its search engine, leveraging Python's fast prototyping abilities and extensive libraries. Dropbox employs Python for its backend services, benefiting from Python's ease of integration and object-oriented design to handle large-scale data processing tasks efficiently .

Python's open-source nature allows for continuous improvement and adaptation through community-driven contributions and the development of new libraries. Community support facilitates quicker bug fixes, extensive documentation, and frameworks, which make Python adaptable to emerging technologies such as machine learning and data science. This adaptability ensures Python remains relevant and ahead in modern computing environments .

Python supports IoT applications through libraries that enable rapid development and integration with IoT platforms. Its simplicity and readability make it suitable for prototyping. Libraries like 'MicroPython' and 'Zerynth' allow Python to run on microcontrollers, facilitating IoT deployments. Python’s extensive libraries for handling data and interoperability with various communication protocols make it well-suited for IoT .

Python IDLE offers a simple and user-friendly interface, ideal for beginners. It provides basic features such as syntax highlighting, code completion, and auto-indentation. These features facilitate learning and ease the transition to more advanced IDEs. IDLE's interactive shell allows immediate experimentation with Python code, which is useful for grasping programming concepts quickly .

Python's emphasis on code readability allows programmers to express concepts in fewer lines of code and makes it easier to read and debug Python scripts. Python was designed with a syntax that removes unnecessary clutter, making maintenance simpler and improving comprehension, thus reducing time spent on debugging .

You might also like