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

Python Fundamentals

The document provides an overview of Python programming, covering its definition, programming languages, and the differences between interpreted and compiled languages. It highlights Python's advantages, such as ease of use and cross-platform compatibility, as well as its disadvantages, including slower execution times compared to compiled languages. Additionally, it discusses Python's character set, tokens, keywords, identifiers, literals, operators, and punctuators.

Uploaded by

anitajha1243
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)
3 views

Python Fundamentals

The document provides an overview of Python programming, covering its definition, programming languages, and the differences between interpreted and compiled languages. It highlights Python's advantages, such as ease of use and cross-platform compatibility, as well as its disadvantages, including slower execution times compared to compiled languages. Additionally, it discusses Python's character set, tokens, keywords, identifiers, literals, operators, and punctuators.

Uploaded by

anitajha1243
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
You are on page 1/ 9

1.

GETTING STARTED WITH PYTHON

PROGRAM

• The set of instruction given to the computer in order to perform a specific task is called
the program.

COMPUTER PROGRAMMING

• It is process that enables us to develop from an original formulation of a computing


problems to the executable program.
• This involves activities like :
o Analysis
o Understanding and solving problem to result in algorithm.
o Verification of requirement of algorithm like correctness, resource utilization etc.
o Coding
o Testing
o Debugging
o Integration
o Implementation
• Main purpose behind the programming is to find sequence of instructions that will
automate performing a specific task and solve a given problem.
• Computers can perform a variety of tasks because they can be programmed. This means
that computer is not designed to do just one task but to do any type of task or job that
program tells it to do.

PROGRAMMING LANGUAGE

• A programming language is a computer language that is used by programmers


(developers) to communicate with computers.
• It is a vocabulary set of grammatical rules for instructing a computer or computing
devices to perform specific task.
• It usually refers to high level languages.
• There are many programming languages such as C, C++, Java, VB.net, Swift, Python,
JavaScript etc.

HIGH LEVEL LANGUAGE


• Sometimes abbreviated as HLL.
• A high level language is a computer programming language, designed for a specific job
and is easier to understand.
• It is more like human language and less like machine language. However for a computer
to understand and run a program created with a high-level language. It must be
compiled or interpreted into machine language.

MACHINE LANGUAGE

• It is the elemental language of computers.


• It is read by the computers central processing unit and it is composed of digital
binary numbers and looks like a very long sequence of zeroes and ones.

COMPILATION

• Compilation is the process the computer takes to convert a high-level programming


language into a machine language that the computer can understand.
• The software which performs the conversion is called a compiler.
• Compiled languages are: C, C++ and Java.

INTERPRETATION

• Interpretation is also the process to convert a high-level programming language into a


machine language that the computer can understand, but the difference is it translates
one statement at a time into machine code.
• The software which performs the conversion is called an interpreter.
• Interpreted languages are: Python, JavaScript, Ruby.

INTERPRETER VS COMPILER

INTERPRETER COMPILER
Translate Program one statement at a time. Scans the entire program and translates it as a
whole into machine code
It takes less amount of time to analyze the It takes large amount of time to analyze the
source code but the overall execution time is source code but the overall execution time is
slower. comparatively faster.
No intermediate object code is generated, Generates intermediate object code which
hence are memory efficient. further requires linking, hence requires more
memory.
Continues translating the program until the It generates the error message only after
first error is met, in which case it stops, hence scanning the whole program. Hence
debugging is easy. debugging is comparatively hard.
Programming language like Python, Ruby use Programming language like C, C++ use
interpreters. compilers.

-----------------------------------------------------------------------------------------------------------------------------

PYTHON INTRODUCTION

• Python is an Interpreted, high-level, general purpose programming language developed


by Guido Van Rossum and its first version was released in February, 1991.
• Python is based on or influenced with two programming languages, ABC language and
Modula-3.
• It is very simple and easy to learn object-oriented programming language, which means
the time needed to learn Python is shorter than for many other languages.

WHY IS IT CALLED PYTHON?

• While you may know the Python as a large snake, the name of the Python Programming
language comes from an old BBC television comedy show Monty Python’s flying circus
from the 1970s.
• Van Rossum thought he needed a name that was short, unique, and slightly mysterious,
so he decided to call the language Python.

PYTHON PLUSES (ADVANTAGES)

EASY TO USE

• Python is compact and very easy to use Object Oriented Programming Language with
very simple syntax rules. There is no use of the semicolon or curly-bracket.
• It is a very high-level language and thus very-very programmer friendly.

EXPRESSIVE LANGUAGE

• Python is very expressive when compared to other languages. By expressive, we men, in


Python a single line of code performs a lot more than what multiple lines can perform in
other languages.
• A simple example, the hello world program you simply type print(“Hello World”). It will
take only one line to execute, while Java or C takes multiple lines.
In C++ : Swap Values In Python : Swap Values
int a=2, b=3, tmp; a, b = 2, 3
tmp=a; a, b = b, a
a=b;
b=tmp;

INTERPRETED LANGUAGE

• Python is an interpreted language, not a compiled language. It means the Python


program is executed one line at a time. The advantage of being interpreted language, it
makes Python an easy to debug language and thus suitable for beginners to advanced
users.

ITS COMPLETENESS

• For Most types of required functionalities is available through various modules of


Python standard library.
• For example, for diverse functionality such as emails, web development, network
connections and many more. Everything is available in Python standard library.
• Thus it is also called Python follows, “Batteries included” philosophy which conveys the
idea that Python comes with everything you need.

CROSS-PLATFORM LANGUAGE

• Python can run equally well on different platforms such as Windows, Linux, UNIX, and
Macintosh etc. So, we can say that Python is a portable language. It enables
programmers to develop the software for several competing platforms by writing a
program only one.

FREE AND OPEN SOURCE

• Python is freely available for everyone. It is freely available on its official website
www.python.org. The open source means, “Anyone can download its source code
without paying any penny.”

VARIETY OF USAGE/APPLICATIONS

• Python has evolved into a powerful, complete and useful language over these years.
These days Python is being used in many diverse fields/applications. some of which are:
o Scripting
o Game Development
o Database Applications
o Rapid Prototyping
o Web Applications
o GUI Programs
o System Administration

PYTHON MINUSES (DISADVANTAGES)

NOT THE FASTEST LANGUAGE

• Python is an interpreted language not a fully compiled one. Fully compiled languages
are faster than their interpreted counterparts.
• So, Python offers faster development times but execution- times are not that fast
compared to some compiled languages.

LESSER LIBRARIES THAN C, JAVA, PERL

• Python offers library support for almost all computing programmes, but its library is still
not competent with languages like C, Java, Perl as they have larger collection available.
• Sometimes in some cases, these languages offer better and multiple solutions than
Python.

NOT STRONG ON TYPE-BINDING

• Python interpreter is not very strong on catching “Type-Binding” issues. For Example, if
you declare a variable as integer but later store a string value in it. Python won’t
complain to pin-point it.

NOT EASILY CONVERTIBLE

• Because of its lack of syntax, Python is an easy language to program, But this advantage
has a flip-side too. It becomes a disadvantage when it comes to translating a program
into another programming language.
• This is because most other languages have structured defined syntax.
2. PYTHON FUNDAMENTALS

PYTHON CHARACTER SET

• Character set is a set of valid characters that a language can recognize.


• A character represents any letter, digit or any other symbol.
• Python has the following character sets:
o Letter – A to Z, a to z
o Digits – 0 to 9
o Special Symbols - + * / etc
o Whitespaces – Blank Space, tab, carriage return, newline, formfeed.
o Other characters – Python process all ASCII and Unicode characters as part of data
or literals.

TOKENS

• The smallest individual unit in a program is known as a Token or lexical unit.


• Python has the following tokens:
I. Keywords
II. Identifiers
III. Literals/Values
IV. Operators
V. Punctuators

KEYWORDS

• Keywords in Python are special reserved words that have got predefined meaning and
purposes and can’t be used for anything but those specific purposes.
• We cannot use a keyword as a variable name, function name or any other identifier.
• E.g : int, float, if, else, elif, continue, import etc.
• All the keywords in Python are written in lowercase except True and False.

IDENTIFIERS (NAMES)

• An identifier is a name given to entities like Variables, Objects, Classes, Functions, Lists,
Dictionaries etc.
• Rules for writing identifiers:
o An identifier can be of any length.
o An identifier cannot start with a digit.
o Keywords cannot be used as identifiers.
o We cannot use special symbols.
o Identifiers can be a combination of Letters, Digits, and Underscore.

LITERALS/VALUES

• Literals are data items that have a fixed/constant value.


• Python allows several kinds of literals
o String Literals
o Numeric literals
o Boolean literals
o Special literals (None)

String Literals:

• A string literal can be created by writing a text (a group of characters) surrounded by


o Single(“ “)
o Double (“ “), or
o Triple quotes(“’ “’)
• By using triple quotes we can write multi-line strings or display in the desired way.

Numeric Literals

• They are immutable and there are three types of numeric literals
o Integer
o Float
o Complex
• Integer: Integers are positive or negative whole numbers with no decimal point. The
Integer literal can be written in,
o Decimal Form - an integer beginning with digits 1-9.
o Binary Form – Integer having only two digits 0 and 1, and beginning with 0b.
o Octal Form - an integer beginning with 0o. (0-7)
o Hexadecimal Form – an integer beginning with 0x. (0-9) (A-F)
• Float: These are real numbers having both integer and fractional parts. ex – 98.5.
• Complex: Complex literal is a way to represent complex numbers. Complex numbers are
numbers that consist of a real part and an imaginary part, where the imaginary part is
represented with a suffix ‘j’ or ‘J’. ex – z=3+4j

Boolean Literals

• Boolean literal is used to represent the two Boolean values , i.e True or False. True
represents the value 1 and False represents the value as 0.

Special Literal (None)

• Python has one special literal which is used to indicate absence of value.

OPERATORS

• These are the signs and symbols that performs certain operations.
• The Parameter on which the operations is performed is called the operands.
• A+B, where + is operator and B is operands.
• Python language many types of operators. They are,
o Arithmetic operators (+, -, *, /, %, **, //)
o Comparison (relational) operators (==, !=, >, <, >=,<=)
o Assignment operators (=)
o Arithmetic assignment operators (+=, -=, *=, /=, %=, **=, //=)
o Logical Operators (Logical AND(and), Logical OR (or), Logical NOT (not))
o Membership operators (in, not in) (in checks if a values exists in a sequence (list,
tuple, dictionary etc) (not in checks if a value does not exist in a sequence
o Identity operators (is, is not) (is checks if the references of two objects are the
same) (is not checks if the references of two objects are not the same)
o Bitwise operators (Bitwise AND (&), Bitwise OR (|), Bitwise XOR (^), Bitwise Not
(~), Left shift (<<), Right shift (>>)

PUNCTUATORS

• Punctuators refers to the symbols used for punctuation or separation of different


elements within the code. ( parantheses (), square brackets [], curly braces {}, Colon :,
Comma , etc)

You might also like