0% found this document useful (0 votes)
309 views4 pages

Python Programming Basics and Concepts

Uploaded by

GAYATHRI SHIYAM
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)
309 views4 pages

Python Programming Basics and Concepts

Uploaded by

GAYATHRI SHIYAM
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

INTRODUCTION TO PYTHON

A Program is a set of instructions that tells the computers what to do in order to come up with a solution for
a particular problem.
When you instruct a computer to perform specific tasks then this is called Computer Programming.

Introduction to Python
Python is a widely used general-purpose, high level programming language. It was initially designed by
Guido van Rossum in 1991 and developed by Python Software Foundation. It was mainly developed for
emphasis on code readability, and its syntax allows programmers to express concepts in fewer lines of code.
Python is a programming language that lets you work quickly and integrate systems more efficiently.
Why to use Python:
1. Python is object-oriented Structure supports such concepts as polymorphism, operation overloading and
multiple inheritance.
2. Indentation Indentation is one of the greatest features in python
3. It’s free (open source) Downloading python and installing python is free and easy
4. It’s Powerful
Dynamic typing Built-in types and tools Library utilities Third party utilities (e.g. Numeric,
NumPy) Automatic memory management
5. It’s Portable
Python runs virtually every major platform used today As long as you have a compatible python
interpreter installed, python programs will run in exactly the same manner, irrespective of platform.
6. It’s easy to use and learn
No intermediate compile Python Programs are compiled automatically to an intermediate form called
byte code, which the interpreter then reads. This gives python the development speed of an interpreter
without the performance loss inherent in purely interpreted languages. Structure and syntax are pretty
intuitive and easy to grasp.
7. Interpreted Language Python is processed at runtime by python Interpreter
8. Interactive Programming Language Users can interact with the python interpreter directly for writing the
programs
9. Straight forward syntax the formation of python syntax is simple and straight forward which also makes
it popular.
There are two modes for using the Python interpreter: • Interactive Mode • Script Mode
Variables: Variables are nothing but reserved memory locations to store values. This means that when you
create a variable you reserve some space in memory. Based on the data type of a variable, the interpreter
allocates memory and decides what can be stored in the reserved memory. Therefore, by assigning different
data types to variables, you can store integers, decimals or characters in these variables.
Run a Program by pressing F5 or by clicking Run→Run Module in Script mode.
Rules for Python variables:
• A variable name must start with a letter or the underscore character
• A variable name cannot start with a number
• A variable name can only contain alpha-numeric characters and underscores
(A-z, 0-9, and _ )
• Variable names are case-sensitive (age, Age and AGE are three different variables)
Assigning Values to Variables: Python variables do not need explicit declaration to reserve memory space.
The declaration happens automatically when you assign a value to a variable. The equal sign (=) is used to
assign values to variables. The operand to the left of the = operator is the name of the variable and the
operand to the right of the = operator is the value stored in the variable.
For example –
a= 100 # An integer assignment
b = 1000.0 # A floating point
c = "Raj" # A string
print (a)
print (b)
print (c)
This produces the following result − 100 1000.0 Raj
Data types:
The data stored in memory can be of many types. For example, a student roll number is stored as a numeric
value and his or her address is stored as alphanumeric characters. Python has various standard data types that
are used to define the operations possible on them and the storage method for each of them.
Int: Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length.
>>> print(24656354687654+2)
24656354687656
Float:
Float, or "floating point number" is a number, positive or negative, containing one or more decimals. Float
can also be scientific numbers with an "e" to indicate the power of 10.
>>> y=2.8
>>> y
2.8
String:
1. Strings in Python are identified as a contiguous set of characters represented in the quotation marks.
Python allows for either pairs of single or double quotes.
• 'hello' is the same as "hello".
• Strings can be output to screen using the print function.
For example: print("hello")
>>> print ("Chinmaya Vidyalaya")
Chinmaya Vidyalaya
Python Comments
A Comment is text that doesn't affect the outcome of a code, it is just a piece of text to let someone know
what you have done in a program or what is being done in a block of code.

Python Operators
Operators are special symbols which represent computation. They are applied on operand(s), which can be
values or variables. Same operators can behave differently on different data types. Operators when applied
on operands form an expression. Operators are categorized as Arithmetic, Relational, Logical and
Assignment. Value and variables when used with operator are known as operands.
Arithmetic Operators

3
Comparison operators

Logical operators

Assignment operators

Type Conversion: The process of converting the value of one data type (integer, string, float, etc.) to
another data type is called type conversion. Python has two types of type conversion. 1. Implicit Type
Conversion 2. Explicit Type Conversion
Implicit Type Conversion:
In Implicit type conversion, Python automatically converts one data type to another data type. This process
doesn't need any user involvement.
Explicit Type Conversion:
In Explicit Type Conversion, users convert the data type of an object to required data type. We use the
predefined functions like int(), float(), str(), etc to perform explicit type conversion. This type of conversion
is also called typecasting because the user casts (changes) the data type of the objects.

Common questions

Powered by AI

Type conversion in Python is essential for ensuring data is in the right format for operations. Implicit conversion is automatically handled by Python when it deems necessary, ensuring seamless execution of operations. Explicit conversion, or typecasting, requires the programmer to explicitly convert types using functions like int(), float(), and str() to manage data types specifically and accurately .

Python automatically manages memory allocation during variable assignment, determining the type of reserved memory space based on the value assigned. This implies the language alleviates the programmer's concern over explicitly declaring variable types, potentially improving performance by reducing memory leaks and errors, though it can introduce overhead due to garbage collection .

Python's portability means that its programs can run on various platforms (Windows, macOS, Linux) with minimal or no modification as long as a compatible interpreter is installed. This reduces platform-specific development overhead, allowing developers to focus on software features and business logic, thus expediting the cross-platform development cycle .

Indentation in Python is used to define the structure of code blocks, such as functions and loops, rather than using braces or keywords as in other programming languages. This enforces consistent, clean code formatting that enhances readability and ensures logical flow, thereby reducing syntax-related errors and improving maintainability .

Python emphasizes code readability, allowing programmers to express concepts in fewer lines of code. This makes Python easy to learn and understand, reducing the time required to develop and maintain software. As a result, Python improves programming efficiency and the overall developer experience .

Python supports both interactive mode, which allows real-time execution and direct interaction with the interpreter, and script mode, which enables the execution of entire programs. This dual approach gives developers flexibility: they can quickly test small code snippets or scripts in interactive mode, while using script mode for larger, complete applications. This enhances efficiency in different stages of development .

Python does not require intermediate compilation; it compiles code directly into bytecode, which the Python interpreter executes. This process gives Python the development speed of light-weight scripting languages while maintaining performance advantages over purely interpreted languages, allowing for rapid prototyping and iteration without typical compile-time delays .

As an interpreted language, Python is executed line by line at runtime, which simplifies debugging and shortens development cycles with immediate feedback. However, this can also lead to slower execution times compared to compiled languages, which optimizes the entire code in advance. Thus, while Python excels in development convenience, it might lag in performance for compute-intensive tasks .

Polymorphism in Python allows for the same function or method to operate on different types of objects. It supports object-oriented programming by enabling objects to be manipulated in a uniform way, regardless of their specific class type, thus promoting design patterns that are both flexible and reusable .

Python's dynamic typing allows developers to write more flexible and concise code, as variables do not need to have type declarations. This, alongside Python's rich set of built-in types and tools, enhances its usability by supporting a wide range of programming paradigms and making the integration and handling of data seamless .

You might also like