Introduction to Python Programming

100% found this document useful (5 votes)
462 views4 pages
Python is a high-level, general-purpose, interpreted programming language. It is often used for web applications, desktop applications, games, and scientific computing. Python code is compil…

Uploaded by

Neshkey

2.

0 Introduction to Python Programming Language

Python is a general-purpose interpreted, interactive, object-oriented and high-level programming


language. Python was created by Guido van Rossum in the late eighties and early nineties. Like
Perl, Python source code is also now available under the GNU General Public License (GPL).

Python is a high-level, interpreted, interactive and object-oriented scripting language. Python


was designed to be highly readable which uses English keywords frequently where as other
languages use punctuation and it has fewer syntactical constructions than other languages.

 Python is Interpreted: This means that it is processed at runtime by the interpreter and
you do not need to compile your program before executing it. This is similar to PERL
and PHP.
 Python is Interactive: This means that you can actually sit at a Python prompt and
interact with the interpreter directly to write your programs.
 Python is Object-Oriented: This means that Python supports Object-Oriented style or
technique of programming that encapsulates code within objects.
 Python is Beginner's Language: Python is a great language for the beginner
programmers and supports the development of a wide range of applications from simple
text processing to WWW browsers to games.

Who uses Python and what for?

Python is used for everything! For example:


“massively multiplayer online role-playing games” like Eve Online, science fiction’s answer to
World of Warcraft, web applications written in a framework built on Python called “Django”,
desktop applications like Blender, the 3-d animation suite which makes considerable use of
Python scripts, the Scientific Python libraries (“SciPy”), instrument control and embedded
systems.

Page 1 of 4
What sort of Language is Python?

The naïve view of computer languages is that they come as either compiled languages or
interpreted languages.

At the strictly compiled end languages like C, C++ or Fortran are "compiled"
(converted) into raw machine code for your computer. You point your CPU at that code and it
runs.

Slightly separate from the strictly compiled languages are languages like Java and C# (or
anything running in the .net framework). You do need to explicitly compile these programming
languages but they are compiled to machine code for a fake CPU which is then emulated on
whichever system you run on.

Then there is Python. Python does not have to be explicitly compiled but behind the scenes there
is a system that compiles Python into an intermediate code which is stashed away to make things
faster in future. But it does this without you having to do anything explicit yourself. So from the
point of view of how you use it you can treat it as a purely interpreted language like the shell or
Perl.

Page 2 of 4
Python first Command

After the typing the command above, press the return key.

Look at these Python Commands:

This is our first Python “function”. A function takes some input, does something with it and
(optionally) returns a value. The nomenclature derives from the mathematics of functions, but we
don’t need to fixate on the mathematical underpinnings of computer science in this course.

Our function in this case is “print” and the command necessarily starts with the name of the
function. The inputs to the function are called its “arguments” and follow the function inside
round brackets (“parentheses”). In this case there is a single argument, the text to print.

Note that Python, as with many but not all programming languages, is “case sensitive”. The word
“print” is not the same as “Print” or “PRINT”.

Page 3 of 4
Use of quotes: “do-print-this”

If there are no quotes then Python will try to interpret the letters as something it should know
about. With the quotes Python simply interprets it as literal text.

For example, without quotes the string of characters p-r-i-n-t are a command; with quotes
they are the text to be printed. i.e, “print” and print

Python Scripts

Let’s create a test Python script - create a file called [Link] with the following contents.

Make a folder – PythonScripts in Directory D:

In that folder, create a new notepad file [Link]

In this file write the following:

#! python

print ("Hello World!")

print ("Programming is fun!")

A Python script can be executed at command line by invoking the interpreter on your
application.

On the command line interface, change directory (cd) to D:

Navigate to the directory where you have saved your python scripts, i.e, PythonScripts

Use the command: cd PythonScripts – then press enter key on the keyboard.

Refer to this link for online tutorials: [Link]

Page 4 of 4

Common questions

Powered by AI

In explicitly compiled languages like C or Java, source code is transformed into machine code through a manual compilation process before execution . This involves translating the entire code to machine code that the CPU can execute. In contrast, Python performs an implicit compilation behind the scenes, converting code into an intermediate bytecode without requiring explicit user intervention . This bytecode is executed by the Python interpreter, which gives Python the appearance of being a purely interpreted language . This hidden compilation provides a balance between the ease of interpreted languages and the performance benefits of compiled languages.

Python's licensing under the GNU General Public License (GPL) allows it to be freely distributed and modified, promoting open-source collaboration and development . This encourages a community-driven approach to software enhancement, where improvements can be shared across global developers. However, the GPL requires that any distributed modified versions are also freely available under the same license terms, ensuring continued open access . This requirement can influence commercial use, as it necessitates sharing improvements indefinitely, impacting proprietary software development.

When writing a Python script, it is important to consider Python's case sensitivity. Keywords and function names must be written in the correct case; for example, "print" is recognized by the interpreter, while "Print" or "PRINT" would result in an error . Additionally, using quotes correctly is crucial since unquoted text is interpreted as a command, while quoted text is treated as a string to be printed . Attention to these details helps prevent common syntax errors and ensures the script runs as intended.

Functions in Python are defined blocks of code designed to perform specific tasks. They take inputs known as 'arguments' and can return a value after execution . The function 'print' demonstrates this, where it accepts its argument within parentheses, such as a text string to output . Python functions derive their name from mathematical functions but do not require deep knowledge of mathematics for their application . Their components include the function name, the parentheses to enclose arguments, and the block of code defining the function's behavior.

Python's simplicity and readability make it an excellent choice for beginners, providing intuitive syntax that resembles everyday language and reducing entry barriers for new programmers . Its widespread use across diverse applications—from web development to data science—offers beginners practical experience in a language that's broadly applicable. However, one potential drawback is that beginners may become less familiar with the complexities of memory management and system architecture, which are more apparent in languages like C or C++ . While Python abstracts many programming complexities to simplify learning, this abstraction can obscure certain fundamental programming concepts.

Python is defined by several key features: it is an interpreted language, meaning code is executed line by line directly without prior compilation, similar to Perl and PHP . Its interactive nature allows users to use the Python prompt to directly execute commands, engage with variables, and receive immediate feedback . Python is object-oriented, supporting encapsulation of code within objects, akin to many modern object-oriented languages like Java and C# . Python's high readability is facilitated by its use of English keywords over punctuation, contrasting with languages like C++ which use more syntactic symbols . Additionally, Python is particularly beginner-friendly, making it accessible for new programmers, unlike more complex languages like C++ or Java .

Encapsulation in Python's object-oriented programming involves bundling data and methods that operate on the data within a single unit known as an 'object' . This encapsulation provides a clear modular structure for code, allowing for the careful control of data access and modification through methods, thereby enhancing code maintainability and security . It logically organizes code into a manageable hierarchy, facilitating both code reuse and abstraction, which conceals complex details while providing a simple interface for interaction.

Python is used in a variety of application domains. In gaming, it's utilized for developing massively multiplayer online role-playing games like 'Eve Online' . The web development field sees Python applied through frameworks like Django to create robust web applications . For desktop applications, Python scripting powers software such as Blender, a 3D animation tool . In scientific computing, libraries like SciPy facilitate complex numerical computations . Python is also used in instrument control and embedded systems, showcasing its versatility across different technological domains .

To execute a Python script from the command line, a user must first navigate to the directory containing the script file . For example, if a script named "hello.py" is saved in 'PythonScripts' on drive D, the user should change the directory to 'D:\PythonScripts' using the command 'cd PythonScripts' . Once in the correct directory, the user can invoke the Python interpreter followed by the script name to execute it . This process allows the script to run, displaying any print outputs in the command line interface.

An interpreted language like Python processes code line by line at runtime, which allows for dynamic execution and easier debugging as errors are encountered immediately . Languages such as C, which are strictly compiled, require the entire code to be translated into machine code before any execution, often resulting in faster performance but more complex debugging since the entire codebase must be navigated to locate errors . Python balances these characteristics by compiling to intermediate bytecode invisible to the user, thus combining elements of both interpreted and compiled languages while maintaining ease of use and flexibility.

Page 1 of 4 
 
2.0  
Introduction to Python Programming Language 
 
Python is a general-purpose interpreted, interactive, obj
Page 2 of 4 
 
What sort of Language is Python? 
 
 
The naïve view of computer languages is that they come as either compile
Page 3 of 4 
 
Python first Command 
 
After the typing the command above, press the return key. 
 
Look at these Python Comm
Page 4 of 4 
 
Use of quotes: “do-print-this” 
If there are no quotes then Python will try to interpret the letters as someth

You might also like