import this
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
print('Hello World')
Hello World
a = 10
print(a)
10
a+10
print('This is First')
print(a+10)
a+20
print(a+30)
a+40
This is First
20
40
a
# NUmber are 5 Types
# Booleans,Integers, Rational, Real, Complex
a = 10
print(type(a))
<class 'int'>
int('100',10)
int('ff', 16)
# Java, C, C++
# short, byte, int, short int, long
# int =
2**(8*4)
# int a = 3000000000
# a = 'Hello'
a = 10
a = 'Hello'
import sys
sys.getsizeof(0)
help(int)
Help on class int in module builtins:
class int(object)
| int([x]) -> integer
| int(x, base=10) -> integer
|
| Convert a number or string to an integer, or return 0 if no arguments
| are given. If x is a number, return x.__int__(). For floating point
| numbers, this truncates towards zero.
|
| If x is not a number or if base is given, then x must be a string,
| bytes, or bytearray instance representing an integer literal in the
| given base. The literal can be preceded by '+' or '-' and be surrounded
| by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
| Base 0 means to interpret the base from the string as an integer literal.
| >>> int('0b100', base=0)
| 4
|
| Methods defined here:
|
| __abs__(self, /)
| abs(self)
|
| __add__(self, value, /)
| Return self+value.
|
| __and__(self, value, /)
| Return self&value.
|
| __bool__(self, /)
| self != 0
|
| __ceil__(...)
| Ceiling of an Integral returns itself.
|
| __divmod__(self, value, /)
| Return divmod(self, value).
|
| __eq__(self, value, /)
| Return self==value.
|
| __float__(self, /)
| float(self)
|
| __floor__(...)
| Flooring an Integral returns itself.
|
| __floordiv__(self, value, /)
| Return self//value.
|
| __format__(self, format_spec, /)
| Default object formatter.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __index__(self, /)
| Return self converted to an integer, if self is suitable for use as an index into a list.
|
| __int__(self, /)
| int(self)
|
| __invert__(self, /)
| ~self
|
| __le__(self, value, /)
| Return self<=value.
|
| __lshift__(self, value, /)
| Return self<<value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __neg__(self, /)
| -self
|
| __or__(self, value, /)
| Return self|value.
|
| __pos__(self, /)
| +self
|
| __pow__(self, value, mod=None, /)
| Return pow(self, value, mod).
|
| __radd__(self, value, /)
| Return value+self.
|
| __rand__(self, value, /)
| Return value&self.
|
| __rdivmod__(self, value, /)
| Return divmod(value, self).
|
| __repr__(self, /)
| Return repr(self).
|
| __rfloordiv__(self, value, /)
| Return value//self.
|
| __rlshift__(self, value, /)
| Return value<<self.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __ror__(self, value, /)
| Return value|self.
|
| __round__(...)
| Rounding an Integral returns itself.
| Rounding with an ndigits argument also returns an integer.
|
| __rpow__(self, value, mod=None, /)
| Return pow(value, self, mod).
|
| __rrshift__(self, value, /)
| Return value>>self.
|
| __rshift__(self, value, /)
| Return self>>value.
|
| __rsub__(self, value, /)
| Return value-self.
|
| __rtruediv__(self, value, /)
| Return value/self.
|
| __rxor__(self, value, /)
| Return value^self.
|
| __sizeof__(self, /)
| Returns size in memory, in bytes.
|
| __str__(self, /)
| Return str(self).
|
| __sub__(self, value, /)
| Return self-value.
|
| __truediv__(self, value, /)
| Return self/value.
|
| __trunc__(...)
| Truncating an Integral returns itself.
|
| __xor__(self, value, /)
| Return self^value.
|
| bit_length(self, /)
| Number of bits necessary to represent self in binary.
|
| >>> bin(37)
| '0b100101'
| >>> (37).bit_length()
| 6
|
| conjugate(...)
| Returns self, the complex conjugate of any int.
|
| to_bytes(self, /, length, byteorder, *, signed=False)
| Return an array of bytes representing an integer.
|
| length
| Length of bytes object to use. An OverflowError is raised if the
| integer is not representable with the given number of bytes.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value.
| signed
| Determines whether two's complement is used to represent the integer.
| If signed is False and a negative integer is given, an OverflowError
| is raised.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_bytes(bytes, byteorder, *, signed=False) from builtins.type
| Return the integer represented by the given array of bytes.
|
| bytes
| Holds the array of bytes to convert. The argument must either
| support the buffer protocol or be an iterable object producing bytes.
| Bytes and bytearray are examples of built-in objects that support the
| buffer protocol.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value.
| signed
| Indicates whether two's complement is used to represent the integer.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs) from builtins.type
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| denominator
| the denominator of a rational number in lowest terms
|
| imag
| the imaginary part of a complex number
|
| numerator
| the numerator of a rational number in lowest terms
|
| real
| the real part of a complex number
1 > 1
sys.getsizeof(1231273612365324786532487523895623785328956329874563478952389238945432313723515738921335867586758627562323527384638263)
# int + int = int
# int - int = int
# int * int = int
# int ** int = int
# int/int = float(ALWAYS)
2+2
3-1
10/2
a = 1.0
a
a = True
b = False
0, [], (), {}, None, ''
response = {}
if response:
print('I GOT PRINTED')
else:
print('NU NAAKU YEM PAMPIYALE< da2 sample pampu anni sastuna pampichatle meeru')
print('I WILL ALWASY PRINT')
NU NAAKU YEM PAMPIYALE< da2 sample pampu anni sastuna pampichatle meeru
I WILL ALWASY PRINT
a = 10
b = a
b
a = 20
a, b
a = [10,2,3]
b = a
a[0] = 10
a
b
int = 1
del int
# +, -, /, *, **, //, %, ==
18//4
import math
math.floor(4.999999999999999999999999999999999999999999999999999999999999999999999999999999)
2 == 2.0
a = 0.1
b = 0.3
c = 0.2
if c == b-a:
print('IT SHOULD PRINT RIGHT?')
print(f'{c:.25f}')
0.2000000000000000111022302
print(f'{b-a:.25f}')
0.1999999999999999833466546
from decimal import Decimal
a = Decimal(3)
x = Decimal(10)
b = Decimal(1)
c = Decimal(2)
c/x == (a/x) - (b/x)
sys.getsizeof(1.0)
sys.getsizeof(Decimal(1))
# for(int i=0, i<10, i++)
a = [1,2,3,4,5,6,7,8,9,10,11]
a = 100
a = 10.0
a = 'asdsadas'
for i in range(11,2,-1):
print(i)
11
10
9
8
7
6
5
4
3
a = [1,2,3,4,5,6,7,8,9,10,11]
a[0]
a = input()
while a not in ('0','1','2'):
print('MUSKONI 0 or 1 pettu bey')
a = input()
KeyboardInterrupt: Interrupted by user
a
a = [1,2,3,4,5,6]
for i in a:
print(i)
if i == 5:
break
else:
print('FOR LO ISSUES YEM RAALE')
1
1 HELLO
2
2 HELLO
3
3 HELLO
4
4 HELLO
5
a = 10
b = 2
try:
print(a/b)
except:
print('Zero')
finally:
print('10')
5.0
10
a = 0
b = 2
while a < 3:
print('------------')
a += 1 #1 2
b -= 1 #1 0
try:
res = a / b
except ZeroDivisionError:
print(f'{a}, {b} - division by 0')
res = 0
break
finally:
print(f'{a}, {b} - always executes')
print(f'{a}, {b} - main loop')
else:
print('n\n\nno errors were encountered!')
------------
1, 1 - always executes
1, 1 - main loop
------------
2, 0 - division by 0
2, 0 - always executes
a = 'abc'
a
a[0] = 's'
TypeError: 'str' object does not support item assignment
a = 'abc' + 'bcd'
a
id(a)
a.replace('a','s')
a
b
a = 'abc'
id(a)
a = 'abc' + 'cde'
id(a)
a = (1,2,3,4,5,6)
a
b = [1,2,3,4,5,6]
b
a[0], b[0]
b[0]= 100
b
a = (1, 2, 3, 4, 5, 6)
id(a)
a = a + (2,3)
id(a)
a
b = [1,2,3,4,5,6]
id(b)
b.extend([1,2])
id(b)
b.append([1,2])
b
a = (1,)
a[0]
'sycdnasdydg34638742387&@^$&*@BAYdg s*&@^#@*&# DGs gw8e2#&*(&#@(*$&@!(* GYSGD&*@#^@!(#'
[23,23,4,5,23] #s,a,v,h,y
input(0,1,2)