Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)] on win32x SyntaxError: invalid syntax >>> >>> >>> x=5 >>> type(x) >>> y = float(x%2) >>> y 1.0 >>> type(y) >>> float(x) 5.0 >>> type(y)(x) 5.0 >>> datatype = type(y) >>> datatype(x) 5.0 >>> z = 1 >>> 5.0(z) Traceback (most recent call last): File "", line 1, in 5.0(z) TypeError: 'float' object is not callable >>> type(y)(x)(z) Traceback (most recent call last): File "", line 1, in type(y)(x)(z) TypeError: 'float' object is not callable >>> type(type(y)) >>> type(y) >>> locals() {'__builtins__': , 'y': 1.0, 'z': 1, '__loader__': , 'x': 5, '__package__': None, '__spec__': None, '__name__': '__main__', 'datatype': , '__doc__': None} >>> globals() {'__builtins__': , 'y': 1.0, 'z': 1, '__loader__': , 'x': 5, '__package__': None, '__spec__': None, '__name__': '__main__', 'datatype': , '__doc__': None} >>> vars() {'__builtins__': , 'y': 1.0, 'z': 1, '__loader__': , 'x': 5, '__package__': None, '__spec__': None, '__name__': '__main__', 'datatype': , '__doc__': None} >>> dir() ['__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'datatype', 'x', 'y', 'z'] >>> x = 5+2-y >>> x = x + 5-z >>> x = 0 >>> x 0 >>> x += 1 >>> x 1 >>> x = x + 1 >>> x 2 >>> x -= 1 >>> x 1 >>> x = 2 >>> x **= 3 >>> x 8 >>> print x SyntaxError: invalid syntax >>> print(x) 8 >>> print(x, 15.3) 8 15.3 >>> print(x,15.3) 8 15.3 >>> print(x, 15.3, 0, -x, x-y/2) 8 15.3 0 -8 7.5 >>> print(x, 15.3, 0, -x, x-y/2, end="end of line") 8 15.3 0 -8 7.5end of line >>> print(x, 15.3, 0, -x, x-y/2, sep=",") 8,15.3,0,-8,7.5 >>> print >>> x 8 >>> print >>> help(print) Help on built-in function print in module builtins: print(...) print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False) Prints the values to a stream, or to sys.stdout by default. Optional keyword arguments: file: a file-like object (stream); defaults to the current sys.stdout. sep: string inserted between values, default a space. end: string appended after the last value, default a newline. flush: whether to forcibly flush the stream. >>> help(type) Help on class type in module builtins: class type(object) | type(object_or_name, bases, dict) | type(object) -> the object's type | type(name, bases, dict) -> a new type | | Methods defined here: | | __call__(self, /, *args, **kwargs) | Call self as a function. | | __delattr__(self, name, /) | Implement delattr(self, name). | | __dir__(...) | __dir__() -> list | specialized __dir__ implementation for types | | __getattribute__(self, name, /) | Return getattr(self, name). | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | __instancecheck__(...) | __instancecheck__() -> bool | check if an object is an instance | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | __prepare__(...) | __prepare__() -> dict | used to create the namespace for the class statement | | __repr__(self, /) | Return repr(self). | | __setattr__(self, name, value, /) | Implement setattr(self, name, value). | | __sizeof__(...) | __sizeof__() -> int | return memory consumption of the type object | | __subclasscheck__(...) | __subclasscheck__() -> bool | check if a class is a subclass | | __subclasses__(...) | __subclasses__() -> list of immediate subclasses | | mro(...) | mro() -> list | return a type's method resolution order | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __abstractmethods__ | | __dict__ | | __text_signature__ | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __base__ = | The most base type | | __bases__ = (,) | | __basicsize__ = 412 | | __dictoffset__ = 132 | | __flags__ = -2146675712 | | __itemsize__ = 20 | | __mro__ = (, ) | | __weakrefoffset__ = 184 >>> help(x) Help on int object: class int(object) | int(x=0) -> 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__(...) | | __ge__(self, value, /) | Return self>=value. | | __getattribute__(self, name, /) | Return getattr(self, name). | | __getnewargs__(...) | | __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<>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__(...) | 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(...) | int.bit_length() -> int | | 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. | | from_bytes(...) from builtins.type | int.from_bytes(bytes, byteorder, *, signed=False) -> int | | Return the integer represented by the given array of bytes. | | The bytes 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. | | The byteorder argument determines 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. | | The signed keyword-only argument indicates whether two's complement is | used to represent the integer. | | to_bytes(...) | int.to_bytes(length, byteorder, *, signed=False) -> bytes | | Return an array of bytes representing an integer. | | The integer is represented using length bytes. An OverflowError is | raised if the integer is not representable with the given number of | bytes. | | The byteorder argument determines 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. | | The signed keyword-only argument 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. | | ---------------------------------------------------------------------- | 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 >>> dir() ['__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'datatype', 'x', 'y', 'z'] >>> dir(x) ['__abs__', '__add__', '__and__', '__bool__', '__ceil__', '__class__', '__delattr__', '__dir__', '__divmod__', '__doc__', '__eq__', '__float__', '__floor__', '__floordiv__', '__format__', '__ge__', '__getattribute__', '__getnewargs__', '__gt__', '__hash__', '__index__', '__init__', '__int__', '__invert__', '__le__', '__lshift__', '__lt__', '__mod__', '__mul__', '__ne__', '__neg__', '__new__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', '__round__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', '__rxor__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__truediv__', '__trunc__', '__xor__', 'bit_length', 'conjugate', 'denominator', 'from_bytes', 'imag', 'numerator', 'real', 'to_bytes'] >>> 15.2 15.2 3 >>> 3 3 >>> "This is a string." 'This is a string.' >>> This is a string. SyntaxError: invalid syntax >>> 'This is a string.' 'This is a string.' >>> "This is a string.' SyntaxError: EOL while scanning string literal >>> "This'll be a string with a single quote in it." "This'll be a string with a single quote in it." >>> "This'll be a string with a single quote (') in it." "This'll be a string with a single quote (') in it." >>> 'Here is a string "with double quotes in it".' 'Here is a string "with double quotes in it".' >>> "This'll be a string with a single quote in it and also "double quotes"." SyntaxError: invalid syntax >>> 'This'll be a string with a single quote in it and also "double quotes".' SyntaxError: invalid syntax >>> "This is a string on SyntaxError: EOL while scanning string literal >>> "This is a string on\nmultiple lines" 'This is a string on\nmultiple lines' >>> print("This is a string on\nmultiple lines") This is a string on multiple lines >>> print("The backslash look like this: \") SyntaxError: EOL while scanning string literal >>> print("The backslash look like this: \\") The backslash look like this: \ >>> print("double quote: \", single quote: \'") double quote: ", single quote: ' >>> '''This is a line that spans multiple lines of output.''' 'This is a line\nthat spans multiple lines of\noutput.' >>> print('''This is a line that spans multiple lines of output.''') This is a line that spans multiple lines of output. >>> val= '''This is a line that spans multiple lines of output.''' >>> print(val) This is a line that spans multiple lines of output. >>> type(val) >>> val = 5 >>> type(val) >>> "This is a string" + "made of two parts." 'This is a stringmade of two parts.' >>> "This is a string " + "made of two parts." 'This is a string made of two parts.' >>> "This is a string" + " made of two parts." 'This is a string made of two parts.' >>> "This is a string" + " " + "made of two parts." 'This is a string made of two parts.' >>> print("This is a string", "made of two parts.") This is a string made of two parts. >>> "This is a string" + "made of two parts.", sep=" " SyntaxError: can't assign to operator >>> str1 = "This is a string" >>> str2 = "made of two parts." >>> str1 + " " + str2 'This is a string made of two parts.' >>> str1 'This is a string' >>> str1 += "made of two parts." >>> str1 'This is a stringmade of two parts.' >>> len(str1) 34 >>> str1 = "\"" >>> print(str1) " >>> len(str1) 1 >>> str2 = "" >>> len(str2) 0 >>> str1 = '\n' >>> len(str1) 1 >>> str1 = "This is a string." >>> str1.lower() 'this is a string.' >>> str1 'This is a string.' >>> str2 = str1.lower() >>> str2 'this is a string.' >>> str1 'This is a string.' >>> str1.upper() 'THIS IS A STRING.' >>> str1.find("is") 2 >>> str1[2] 'i' >>> str1[2:4] 'is' >>> str1[2:6] 'is i' >>> str1[str1.find("is"):str1.find("is")+len("is")] 'is' >>> pos = str1.find("is") >>> str1[pos:pos+len("is")] 'is' >>> 'is' in str1 True >>> 'zzz' in str1 False >>> str1.find('zzz') -1 >>> str1.index('zzz') Traceback (most recent call last): File "", line 1, in str1.index('zzz') ValueError: substring not found >>> str1.index('is') 2 >>> str(15) '15' >>> x = '30' >>> type(x) >>> y = int(x) >>> y 30 >>> x '30' >>> type(y) >>> type(x) >>> y 30 >>> str(y) '30' >>> y = "14.3" >>> float(y) 14.3 >>> int(y) Traceback (most recent call last): File "", line 1, in int(y) ValueError: invalid literal for int() with base 10: '14.3' >>> z= float(y) >>> z 14.3 >>> int(z) 14 >>> int(float(y)) 14 >>> z 14.3 >>> str(z) '14.3' >>> 1/3 0.3333333333333333 >>> round(1/3, 2) 0.33 >>> round(5.72934, 2) 5.73 >>> round(5.72934, 0) 6.0 >>> round(5.72934, 15) 5.72934 >>> output = "The total price is $"+15.30 Traceback (most recent call last): File "", line 1, in output = "The total price is $"+15.30 TypeError: Can't convert 'float' object to str implicitly >>> total =15.3 >>> output = "The total price is $"+total Traceback (most recent call last): File "", line 1, in output = "The total price is $"+total TypeError: Can't convert 'float' object to str implicitly >>> output = "The total price is $"+str(total) >>> print(output) The total price is $15.3 >>> str_total = round(total, 2) >>> output = "The total price is $"+str(str_total) >>> print(output) The total price is $15.3 >>> format(total, '.2f') '15.30' >>> float(format(total, '.2f')) 15.3 >>> output = "The total price is $"+format(total, '.2f') >>> print(output) The total price is $15.30 >>> x = format(total, '.2f') >>> type(x) >>> help(format) Help on built-in function format in module builtins: format(...) format(value[, format_spec]) -> string Returns value.__format__(format_spec) format_spec defaults to "" >>> format(total, '.3f') '15.300' >>> format(total, '2f') '15.300000' >>> format(total, 'i') Traceback (most recent call last): File "", line 1, in format(total, 'i') ValueError: Unknown format code 'i' for object of type 'float' >>> format(total, 'd') Traceback (most recent call last): File "", line 1, in format(total, 'd') ValueError: Unknown format code 'd' for object of type 'float' >>> format(total, ".2f") '15.30' >>> format("and", '20s') 'and ' >>>