0% found this document useful (0 votes)
8 views125 pages

Python Scribble

The document provides an overview of Python programming concepts, including variable types, print statements, operators, and data structures such as lists and dictionaries. It also discusses control statements, memory management, and the differences between Python and C programming. Additionally, it covers function definitions, scope, and the importance of comments in code.

Uploaded by

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

Python Scribble

The document provides an overview of Python programming concepts, including variable types, print statements, operators, and data structures such as lists and dictionaries. It also discusses control statements, memory management, and the differences between Python and C programming. Additionally, it covers function definitions, scope, and the importance of comments in code.

Uploaded by

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

-V – current version installed in machine

Anything in angular parenthesis is Mandatory

In square braces is optional

>>>> - Python Prompt

Session variable has scope to the command prompt opened for that instance. It will not alive when the
command prompt is launched again.

Various ways to use the Exit function.


Token – delimiter, keyword, literal, etc

Python – dynamic typing programming language

Shebang - #! – in case the user does not have privilege to run the script, Path of the utility to be used in
executing program. Used for Environment permission.

Scrip comment – high level info

Code comment – written for block of code

All comments has # as prefix – description for program

dynamic programming typing language


Python is Case sensitive and white space sensitive.

Shebang is only for UNIX environment

IO statements

Print – written in double codes is just a display statement.

.PY – denotes python program.

Execution of program.

#!/usr/bin/python ( in windows, it is considered as comment line)

IO statments:

print "hello world"


Variables:

Primitive type and non-primitive type or Unary type and object type (data type)

Type() – function returning the type specification of the variable.


Two types of print statement (It is used to display anything onto the standard output device)

1) Formatted style print – format specifiers (%i, %d, %s)


2) Unformatted style print – Type specification is understood by python itself.

, comma is an append operator.


Format functions also can be used.

Operators:

Arithmetic

Logical

Relational

Shift
Type of value associated is key to differentiate the operators.

Concatenation is used “+” with doubles quotes in variables.

Python does not need line delimiters.

However when multiple statements do be given in single line, then delimiters; can be used.

Multi label and multi value assignment.

Semantics in nature – what u see you is what Python understands.


Use of double quotes and single quotes.
List: Elements can store different type of value. Each element is individual by nature.
Len is a function to retrieve the range of the variable.

HELP function will say more about the LIST. Methods available, attributes, Syntax.
Change the variable

Append() – add one value to the end of the list


Del() – to deference the label with associated element. Or shrink the list.

Insert() – inserts a new value in the index specified.

Insert(Offset, value).

Extend() – to append the 2 variable arbitrarily .


Count () – count
Simple objects and compound objects.
Range() – build a list with given range of values. ( start and step value is optional) (Start,Stop,Step)

It will start from 0 when the start value is not given


Range Operator - Variable [start index:stop index:stepindex]
When no condition is given in the square braces, then it will extract the whole list. When the range is
given, it will extract only the selected range.

Method can be applied only on the object class associated to the method belongs to. Function is applied
on compatible value.
No where in Python has memory duplication.
Dictionary – is un ordered fashion of storage. Uses hashing technique. It is not guaranteed to be stored
in the manner it is entered. It stores the value in pairs.

Keys() – They are like index. Values are those assisted to those keys.
Long is capable of storing octal and hexadecimal values.

Complex number stores imaginary and constant values.

Compound object is type of object which contains another object inside it.
Simple object contains unary values

Although the Type of C shows list. It’s a conceptual understanding that it’s a compound object.
REF count mechanism to manage the memory effectively.

Reference copy is an alias (example in above code


Shallow copy – it will have reference of another referential object.
In Realtime project, interactive programs are not created. It will cause overhead, and it will be optimized
to consume the resources.

Non-Interactive sessions, will read the input in the command line.


+ is for concatenation.
Raw_Input() is available in 2.x and not in 3.x
Control Statements:
Conditional statement – IF

Loop – iterative statement

Library files – which is implicitly included.


The following example is shown comparing the coding for C and Python. Preprocessor statements are
implicit in Python, there is no separate declaration required. There are no braces used in Python unlike C
programming. Instead : (Colon) is used to delimit the control statements.
Four white spaces
Logical operators
s
Data exception handler functions

Built in functions
Lexicography comparison for Strings

Arbitrary value comparison for multiple values in strings.


Dereferencing and referencing
Any variable defined in the Main is global scope by nature

Three types of passing values:

Static pass

Dynamic pass

Expression pass
Function definition and data members in the modules.
Don’t define Shebang lines in the user defined modules. Primary execute file is the consume file.

You might also like