'islower',
'isspace',
'istitle',
'isupper',
'join',
'ljust',
'lower',
'lstrip',
'partition',
'replace',
'rfind',
'rindex',
'rjust',
'rpartition',
'rsplit',
'rstrip',
'split',
'splitlines',
'startswith',
'strip',
'swapcase',
'title',
'translate',
'upper',
'zfill']
In [32]: s
Out[32]: 'Hello World'
In [33]: s.upper()
Out[33]: 'HELLO WORLD'
In [34]: s.replace('o', '0')
Out[34]: 'Hell0 W0rld'
In [35]: help(dir)
Help on built-in function dir in module __builtin__:
dir(...)
dir([object]) -> list of strings
If called without an argument, return the names in the current scope.
Else, return an alphabetized list of names comprising (some of) the attributes
of the given object, and of attributes reachable from it.
If the object supplies a method named __dir__, it will be used; otherwise
the default dir() logic is used and returns:
for a module object: the module's attributes.
for a class object: its attributes, and recursively the attributes
of its bases.
for any other object: its attributes, its class's attributes, and
recursively the attributes of its class's base classes.
In [36]: help(s.upper)
Help on built-in function upper:
upper(...)
S.upper() -> string
Return a copy of the string S converted to uppercase.
In [37]: help(len)
Help on built-in function len in module __builtin__:
len(...)
len(object) -> integer
Return the number of items of a sequence or mapping.
In [38]: s
Out[38]: 'Hello World'
In [39]: len(s)
Out[39]: 11
In [40]: help(abs)
Help on built-in function abs in module __builtin__:
abs(...)
abs(number) -> number
Return the absolute value of the argument.
In [41]: abs(42)
Out[41]: 42
In [42]: abs(-42)
Out[42]: 42
In [43]: abs(1 + 3j)
Out[43]: 3.1622776601683795
In [44]: d = 1 + 3j
In [45]: dir(d)
Out[45]:
['__abs__',
'__add__',
'__class__',
'__coerce__',
'__delattr__',
'__div__',
'__divmod__',
'__doc__',
'__eq__',
'__float__',
'__floordiv__',
'__format__',
'__ge__',
'__getattribute__',
'__getnewargs__',
'__gt__',
'__hash__',
'__init__',
'__int__',
'__le__',
'__long__',
'__lt__',
'__mod__',
'__mul__',
'__ne__',
'__neg__',
'__new__',
'__nonzero__',
'__pos__',
'__pow__',
'__radd__',
'__rdiv__',
'__rdivmod__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__rfloordiv__',
'__rmod__',
'__rmul__',
'__rpow__',
'__rsub__',
'__rtruediv__',
'__setattr__',
'__sizeof__',
'__str__',
'__sub__',
'__subclasshook__',
'__truediv__',
'conjugate',
'imag',
'real']
In [46]: d.conjugate()
Out[46]: (1-3j)
In [47]: d.imag
Out[47]: 3.0
In [48]: d.real
Out[48]: 1.0
In [49]: type(d.imag)
Out[49]: float
In [50]: d.conjugate
Out[50]: <function conjugate>
In [51]: d.conjugate()
Out[51]: (1-3j)
In [52]: d.imag()
Traceback (most recent call last):
File "<ipython-input-52-8358abc070f9>", line 1, in <module>
d.imag()
TypeError: 'float' object is not callable
In [53]: 3()
Traceback (most recent call last):
File "<ipython-input-53-c0480d0bce84>", line 1, in <module>
3()
TypeError: 'int' object is not callable
In [54]: 3.()
Traceback (most recent call last):
File "<ipython-input-54-782cbe20571c>", line 1, in <module>
3.()
TypeError: 'float' object is not callable
In [55]: abs(d)
Out[55]: 3.1622776601683795
In [56]: dir(d)
Out[56]:
['__abs__',
'__add__',
'__class__',
'__coerce__',
'__delattr__',
'__div__',
'__divmod__',
'__doc__',
'__eq__',
'__float__',
'__floordiv__',
'__format__',
'__ge__',
'__getattribute__',
'__getnewargs__',
'__gt__',
'__hash__',
'__init__',
'__int__',
'__le__',
'__long__',
'__lt__',
'__mod__',
'__mul__',
'__ne__',
'__neg__',
'__new__',
'__nonzero__',
'__pos__',
'__pow__',
'__radd__',
'__rdiv__',
'__rdivmod__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__rfloordiv__',
'__rmod__',
'__rmul__',
'__rpow__',
'__rsub__',
'__rtruediv__',
'__setattr__',
'__sizeof__',
'__str__',
'__sub__',
'__subclasshook__',
'__truediv__',
'conjugate',
'imag',
'real']
In [57]: type(d.__abs__)
Out[57]: method-wrapper
In [58]: d.__abs__()
Out[58]: 3.1622776601683795
In [59]: abs(d)
Out[59]: 3.1622776601683795
In [60]: help(dir)
Help on built-in function dir in module __builtin__:
dir(...)
dir([object]) -> list of strings
If called without an argument, return the names in the current scope.
Else, return an alphabetized list of names comprising (some of) the attributes
of the given object, and of attributes reachable from it.
If the object supplies a method named __dir__, it will be used; otherwise
the default dir() logic is used and returns:
for a module object: the module's attributes.
for a class object: its attributes, and recursively the attributes
of its bases.
for any other object: its attributes, its class's attributes, and
recursively the attributes of its class's base classes.
In [61]: dir?
Type: builtin_function_or_method
String form: <built-in function dir>
Namespace: Python builtin
Docstring:
dir([object]) -> list of strings
If called without an argument, return the names in the current scope.
Else, return an alphabetized list of names comprising (some of) the attributes
of the given object, and of attributes reachable from it.
If the object supplies a method named __dir__, it will be used; otherwise
the default dir() logic is used and returns:
for a module object: the module's attributes.
for a class object: its attributes, and recursively the attributes
of its bases.
for any other object: its attributes, its class's attributes, and
recursively the attributes of its class's base classes.
In [62]: dir??
Type: builtin_function_or_method
String form: <built-in function dir>
Namespace: Python builtin
Docstring:
dir([object]) -> list of strings
If called without an argument, return the names in the current scope.
Else, return an alphabetized list of names comprising (some of) the attributes
of the given object, and of attributes reachable from it.
If the object supplies a method named __dir__, it will be used; otherwise
the default dir() logic is used and returns:
for a module object: the module's attributes.
for a class object: its attributes, and recursively the attributes
of its bases.
for any other object: its attributes, its class's attributes, and
recursively the attributes of its class's base classes.
In [63]: s
Out[63]: 'Hello World'
In [64]: s.upper()
Out[64]: 'HELLO WORLD'
In [65]: def mysum(a, b):
...: s = a + b
...: return s
...:
In [66]: dir()
Out[66]:
['In',
'Out',
'_',
'_25',
'_26',
'_28',
'_29',
'_30',
'_31',
'_32',
'_33',
'_34',
'_38',
'_39',
'_41',
'_42',
'_43',
'_45',
'_46',
'_47',
'_48',
'_49',
'_50',
'_51',
'_55',
'_56',
'_57',
'_58',
'_59',
'_63',
'_64',
'__',
'___',
'__builtin__',
'__builtins__',
'__name__',
'_dh',
'_i',
'_i25',
'_i26',
'_i27',
'_i28',
'_i29',
'_i30',
'_i31',
'_i32',
'_i33',
'_i34',
'_i35',
'_i36',
'_i37',
'_i38',
'_i39',
'_i40',
'_i41',
'_i42',
'_i43',
'_i44',
'_i45',
'_i46',
'_i47',
'_i48',
'_i49',
'_i50',
'_i51',
'_i52',
'_i53',
'_i54',
'_i55',
'_i56',
'_i57',
'_i58',
'_i59',
'_i60',
'_i61',
'_i62',
'_i63',
'_i64',
'_i65',
'_i66',
'_ih',
'_ii',
'_iii',
'_oh',
'_sh',
'd',
'exit',
'get_ipython',
'mysum',
'quit',
's']
In [67]: def mysum(a, b):
...: s = a + b
...: return s
...:
In [68]: mysum(10, 20)
Out[68]: 30
In [69]: r mysum(10, 20)
File "<ipython-input-69-9d362197e313>", line 1
r mysum(10, 20)
^
SyntaxError: invalid syntax
In [70]: c = mysum(10, 20)
In [71]: c
Out[71]: 30
In [72]: help(mysum)
Help on function mysum in module __main__:
mysum(a, b)
In [73]: runfile('/Users/progprim/Desktop/hello-in-spyder.py', wdir='/Users/progprim/Desktop')
In [74]: runfile('/Users/progprim/Desktop/hello-in-spyder.py', wdir='/Users/progprim/Desktop')
30
In [75]: help(mysum)
Help on function mysum in module __main__:
mysum(a, b)
In [76]: runfile('/Users/progprim/Desktop/hello-in-spyder.py', wdir='/Users/progprim/Desktop')
30
In [77]: help(mysum)
Help on function mysum in module __main__:
mysum(a, b)
This function mysum takes two values
a and b, computes the sum, and returns
the sum.
This is not particularly relevant, but
we are pround to have written our
first function.
Hans Fangohr, fangohr@soton.ac.uk,
17 September 2014
In [78]: a = 10
In [79]: type(a)
Out[79]: int
In [80]: a = 10.0
In [81]: type(a)
Out[81]: float
In [82]: mysum(10, 12)
Out[82]: 22
In [83]: mysum(10.234, 3.23)
Out[83]: 13.464
In [84]: mysum("Hello", "World")
Out[84]: 'HelloWorld'
In [85]: "Hello" + "World"
Out[85]: 'HelloWorld'
In [86]: