31. What is package in Python?
Python has packages for directories and modules for files.
Python package can have sub-packages and modules.
A directory must contain a file named __init__.py
in order for Python to consider it as a package. This file can be left empty but we usually place the initialization code for that package in this file.
32. What are Globals(), Locals() and Reload()?
locals() returns all the names that can be accessed locally from that function.
globals() returns all the names that can be accessed globally from that function.
reload() function imports a previously imported module again.
reload(module_name)
33. What is PyPI?
PyPI is the default software repository for Python developers to store created Python programming language software developers and programmers alike use to publicize and share their software.
PyPI itself also simplifies the Python packaging process for Python programs.
34. What are String in Python?
In Python, string is an immutable sequence data type. A Unicode character sequence wrapped inside single, double, or triple quotes. Some valid string literals in Python are:
a= 'Code window'
b="Code window"
c='''Code window'''
d="""Code window"""
35. What is String Formatting in Python?
The format() method formats the specified value and insert them inside the string’s placeholder.
The place is defined within the curly braces {}.
The format() method returns the formatted string.
txt = "This is {fname}, I'm {age}".format(fname = "codewindow", age = 2)
print(txt)
Output:
This is codewindow, I'm 2
36. Say about Built-in String Methods in Python.
Built-in format() function is a low level implementation for formatting an object using__format__() internally, string format() is a higher level implementation able to perform complex formatting operations on multiple object strings as well.
37. Slicing in String with an Example.
A very powerful technique in python that slices or segment a string according to your need.
b = "codewindow!"
print(b[2:5])
Output:
dew
b = "codewindow!"
print(b[3:])
Output:
ewindow!
b = "codewindow!"
print(b[:6])
Output:
codewi
38. What are Positive and Negative Indexing in Python?
In Python Positive indexing, we pass a positive index that we want to access in square brackets. The index number starts at 0 which denotes the start of a string
In negative indexing in Python, we pass the negative index which we want to access in square brackets. Here, the index number starts from index number -1 which denotes the last character of a string.
str_new = "codewindow"
print(str_new[-1])
Output:
w
str_new = "codewindow"
print(str_new[1])
Output:
o
39. What is the functionality of ord()?
ord() function basically returns an integer representing the Unicode character.
print(ord('P'))
Output:
80
40. What is the functionality of chr()?
chr() method basically returns a string representing a character whose Unicode code (or ASCII) is an integer.
print(chr(71))
Output:
G