Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

P- Parenthesis E-Exponent M- Mul D- Div A- Add S Sub

PEMDAS
Plz excuse my dear an shell
>>> 21/3
7.0
>>> 21/4
5.25
>>> 21//4
5
----------------------------------------------------------------------------------------------------------------------------------------TYPE CASTING STRING INPUT TO INT
The easiest way to obtain user input from the command-line is with the
input() : The INPUT IS TAKEN AS STRING AND NEED TO BE CASTED FOR
STRING TO FLOAT OR INT.
built-in function.
It reads from standard input and assigns the string value to the variable you
designate.
You can use the
int()
built-in function (Python versions older than 1.5 will have to use the string.atoi()
function)
to convert any numeric input string to an integer representation.
>>> user = raw_input('Enter login name: ')
Enter login name: root
>>> print 'Your login is:',
user Your login is: root
The above example was strictly for text input.

A numeric string input (with conversion to a real integer) example follows below:
>>> num = input('Now enter a number: ')
Now enter a number: 1024
>>> print 'Doubling your number: %d' % (int(num) * 2)
Doubling your number: 2048
>>> num = int ( input('Now enter a number: '))

BUILT IN FUNCTION
>>> dir (__builtins__)
dir (__builtins__)
['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException',
'BlockingIOError', 'BrokenPipeError', 'BufferError', 'BytesWarning',
'ChildProcessError', 'ConnectionAbortedError', 'ConnectionError',
'ConnectionRefusedError', 'ConnectionResetError', 'DeprecationWarning',
'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False',
'FileExistsError', 'FileNotFoundError', 'FloatingPointError', 'FutureWarning',
'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning',
'IndentationError', 'IndexError', 'InterruptedError', 'IsADirectoryError',
'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError',
'None', 'NotADirectoryError', 'NotImplemented', 'NotImplementedError',
'OSError', 'OverflowError', 'PendingDeprecationWarning',
'PermissionError', 'ProcessLookupError', 'ReferenceError',
'ResourceWarning', 'RuntimeError', 'RuntimeWarning', 'StopIteration',
'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError',
'TimeoutError', 'True', 'TypeError', 'UnboundLocalError',
'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError',
'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError',
'Warning', 'WindowsError', 'ZeroDivisionError', '__build_class__',
'__debug__', '__doc__', '__import__', '__loader__', '__name__', '__package__',
'__spec__', 'abs', 'all', 'any', 'ascii', 'bin', 'bool', 'bytearray', 'bytes',
'callable', 'chr', 'classmethod', 'compile', 'complex', 'copyright', 'credits',
'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'exec', 'exit', 'filter',
'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help',
'hex', 'id', 'input', 'int', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list',
'locals', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open',
'ord', 'pow', 'print', 'property', 'quit', 'range', 'repr', 'reversed', 'round',

'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple',


'type', 'vars', 'zip']

to see all built in modules type " help( ' modules ' ) "
to see all functions inside a module type
" help('moduleName') "
ex- help('math')

THE BUILT IN FUNCTION CAN BE USED DIRECTLY IN THE PROGRAM


BUT BUILT IN MODULES need to be IMPORTED before using it to the program
>>> import math
>>> math.acosh
<built-in function acosh>
>>> math.acosh(100)
5.298292365610484
>>>
------------------------------------------------------------------------------------------------------------------------------------------Application Programmers Interface
There are two fundamentally different reasons for using the Python/C API. The first reason is to
write extension modules for specific purposes; these are C modules that extend the Python interpreter.
This is probably the most common use. The second reason is to use Python as a component in a larger
application; this technique is generally referred to as embedding Python in an application.
-------------------------------------------------------------------------------------------------------------------------------------------------------

Hash mark ( # ) indicates Python comments

NEWLINE ( \n ) is the standard line separator (one statement per line)


Backslash ( \ ) continues a line
Semicolon ( ; ) joins two statements on a line

Colon ( : ) separates a header line from its suite

Compound or complex statements, such as if, while, def, and class,


are those which require a header line and a suite. Header lines begin
the statement (with the keyword) and terminate with a colon ( : )
and are followed by one or more lines which make up the suite. We
will refer to the combination of a header line and a suite as a clause.

Statements (code blocks) grouped as suites


Suites delimited via indentation
Python files organized as "modules"

Variable Assignment
Equal sign ( = ) is the assignment operator
A variable is like a mailbox. You can put something in the mailbox and check the
contents later. Putting a new value in the mailbox replaces the existing value.
Computer memory is really a very large collection of such boxes. For instance,
256MB of RAM has about 67 million boxes for storing numbers.
Python (and almost all languages) make it easier for us to remember what each box
holds by giving it a name (called an identifier). It is much easier to remember a
variable with a name rather than the fact that box number 4168443356 is storing
the data we want.
Python variables are created by assignment, using the = operator, which is the
process of setting the value of a variable (putting data in the mailbox). Any other
mention of the variable name retrieves the value stored in the variable .

In Python, objects are referenced, so on assignment, a reference (not a value) to an object is


what is being assigned, whether the object was just created or was a pre-existing object.

Also, if you familiar with C, you are aware that assignments are treated as
expressions. This is not the case for Python, where assignments do not
have inherent values. Statements such as the following are invalid in
Python:

>>> x = 1
>>> y = (x = x + 1)

# assignments not expressions!

File "<stdin>", line 1 y = (x = x + 1)


^ SyntaxError: invalid syntax

Beginning in Python 2.0, the equals sign can be combined with an arithmetic
operation and the resulting value reassigned to the existing variable. Known as
augmented assignment,
x=x+1

can now be written as

x += 1
Python does not support pre-/post-increment nor pre-/post-decrement
operators such as x++ or --x.

Multiple Assignment
>>> x = y = z = 1
"Multuple" Assignment

we use "multuple" here because when assigning variables this way, the objects on
both sides of the equals sign are tuples
>>> x, y, z = 1, 2, 'a string'
>>> x
1
>>> y
2
>>> z
'a string'
>>> (x, y, z) = (1, 2, 'a string')

------------------------------------------------------------------------------------------------------------------------# swapping variables in Python DONT REQUIRE TEMPRORY VARIABLE


>>> (x, y) = (1, 2)
>>> x
1 >>> y
2
>>> (x, y) = (y, x)
>>> x
2

>>> y

6220180019400020533
June2006
0031
4890211523129540 corporation
3/13 3/23
5988

You might also like