In [1]:
# Strings are arrays of bytes representing Unicode characters.
#Strings in Python can be created using single quotes or double quotes or even triple quotes.
In [2]:
greetings='Hello'
name='kushagra'
In [3]:
#placeholder can be used to access variable using format method
message="{0}, {1}. welcome!".format(greetings,name)
print(message)
Hello, kushagra. welcome!
In [4]:
#or you can use f string which are new to python.. you need to have python 3.6 or above to use f string
message2=f"{greetings}, {name}. welcome!"
print(message2)
Hello, kushagra. welcome!
In [5]:
#To convert a string to all upper you can use in built method.
variable = "hello"
print(variable.upper())
HELLO
In [8]:
#you can use dir() function which return the list of valid attributes for that object
print(dir(variable))
['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isascii', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
In [15]:
#you can use help function which display the documentation of modules, functions, classes, keywords etc.
print(help(dir))
Help on built-in function dir in module builtins:

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.

None