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

Advance Computer Programming: Notes

Python is an interpreted, dynamic programming language that emphasizes code readability. It uses IDLE as its integrated development environment. Python programs manipulate objects that have types like scalar and non-scalar. It uses keywords like and, for, class and special characters like # for comments. Python supports various data types including integers, floats, strings, lists, tuples and dictionaries. Control structures in Python include sequential statements, decision statements like if/else and repetition statements like for and while loops. Functions are defined using def and can take arguments and recursively call themselves.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Advance Computer Programming: Notes

Python is an interpreted, dynamic programming language that emphasizes code readability. It uses IDLE as its integrated development environment. Python programs manipulate objects that have types like scalar and non-scalar. It uses keywords like and, for, class and special characters like # for comments. Python supports various data types including integers, floats, strings, lists, tuples and dictionaries. Control structures in Python include sequential statements, decision statements like if/else and repetition statements like for and while loops. Functions are defined using def and can take arguments and recursively call themselves.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CS 121

ADVANCE COMPUTER
PROGRAMMING
___

Notes

Introduction to Python

Python

- a widely used high-level, general-purpose, interpreted, dynamic programming language.


- Its design philosophy emphasizes code readability, and its syntax allows programmers to
express concepts in fewer lines of code than possible in languages such as C++ or Java.

IDLE Development Environment

- IDE for Python, used on Windows


- The Python IDE that comes bundled with Python.

Basic Elements, Branching and Control Structures

● Object
- the smallest and core thing that Python programs manipulate. Every object has a
type: Scalar or Non-Scalar.
● Expression
- Objects and operators can be combined to form expressions, each of which
evaluates to an object of some type, which we refer to as value.
● Shell Prompt symbol
- The symbol is >>> which indicates, interpreter is expecting the user to enter
some code of python in the shell.
● Keywords/Reserved Words in Python
- and, with, for, is, raise, assert, from, del, return, break, else, global, lambda, not,
try, except, if, elif, or, class, while, continue, exec, import, finally, pass, as, yield,
def, in, print
● Comments
- # is used to comment in Python.
● Python identifiers
- are user-defined names. They are used to specify the names of variables,
functions, class, module, etc.
● Rules to Create Identifiers
- can’t use reserved keywords as an identifier name
- contain letters in a small case (a-z), upper case (A-Z), digits (0-9), and
underscore (_)
- can’t begin with a digit
- can’t contain only digits
- can start with an underscore
- no limit on the length of the identifier name
- case sensitive
● Valid Identifiers
- ab10c: contains only letters and numbers
- abc_DE: contains all the valid characters
- surprisingly but Yes, underscore is a valid identifier
- abc: identifier can start with an underscore
● Invalid Identifiers
- 99: identifier can’t be only digits
- 9abc: identifier can’t start with number
- x+y: the only special character allowed is an underscore
- for: it’s a reserved keyword
● Multiple Assignments
- Python allows you to assign a single value to several variables simultaneously.
For example −a = b = c = 1
● Python Numbers
- int (signed integers)
- long (long integers, they can also be represented in octal and hexadecimal)
- float (floating point real values)
- complex (complex numbers)
● Python Strings
- identified as a contiguous set of characters represented in the quotation marks.
- allows for either pairs of single or double quotes.
● Python List
- A list contains items separated by commas and enclosed within square brackets
([]).
- lists are similar to arrays in C. One difference between them is that all the items
belonging to a list can be of different data types.
● Python Tuples
- A tuple consists of a number of values separated by commas.
- Unlike lists, however, tuples are enclosed within parentheses.
● Python Dictionary
- kind of hash table type.
- enclosed by curly braces ({ }) and values can be assigned and accessed using
square braces ([]).
● Operators
- the constructs which can manipulate the value of operands.
- Relational operators, compare the values on either sides of them and decide the
relation among them
- Bitwise operator, works on bits and performs bit by bit operation.

Control Structure in Python

1. Sequential statements
- are a set of statements whose execution process happens in a sequence.
- The problem with sequential statements is that if the logic has broken in any one
of the lines, then the complete source code execution will break.
2. Decision control statements or branching statements
- allows a program to test several conditions and execute instructions based on
which condition is true.
- If statements are control flow statements that help us to run a particular code,
but only when a certain condition is met or satisfied. A simple if only has one
condition to check.
- if-else statement evaluates the condition and will execute the body of if the test
condition is True, but if the condition is False, then the body of else is executed.
- Nested if statements are an if statement inside another if statement.
- if-elif-else statement is used to conditionally execute a statement or a block of
statements.
3. Repetition statements
- used to repeat a group(block) of programming instructions.
- for loop is used to iterate over a sequence that is either a list, tuple, dictionary,
on a set.
- while loops are used to execute a block of statements repeatedly until the given
condition is satisfied. Then, the expression is checked again and, if it is still true,
the body is executed again. This continues until the expression becomes false.

Python Functions

- A way of isolating code that is needed in more than one place by refactoring it to make it
much more modular.
- Defined with the def statement or def keyword.

Arguments

- specified after the function name, inside the parentheses. You


- can add as many arguments as you want, just separate them with a comma.

Recursion

- a defined function can call itself.

You might also like