0% found this document useful (0 votes)
2 views48 pages

Session-3 Python Strings

The document covers various aspects of strings in Python, including creation, accessing, editing, and operations on strings. It discusses string functions, methods, and examples of string manipulation, along with time complexity concepts. Additionally, it includes interview questions related to Python fundamentals.

Uploaded by

photo9975
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views48 pages

Session-3 Python Strings

The document covers various aspects of strings in Python, including creation, accessing, editing, and operations on strings. It discusses string functions, methods, and examples of string manipulation, along with time complexity concepts. Additionally, it includes interview questions related to Python fundamentals.

Uploaded by

photo9975
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 48

Session-3

Strings
Today’s Topics:
Strings are sequence of Characters.
OR
In Python specifically, strings are a sequence of
Unicode Characters
 Creating Strings
 Accessing Strings
 Adding Chars to Strings
 Editing Strings
 Deleting Strings
 Operations on Strings
 String Functions

Creating Strings
a = 'single quote'
b = "double quotes"
# multiline strings
c = '''single quote multiline'''
d = """double quotes multline"""
e = str("type casting")
print(a)
print(b)
print(c)

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
print(d)
print(e)

"it's raining outside"


# if you want to use quotes inside another string use
different quotes outside and inside

Example:- Accessing Substrings from a String


Positive Indexing
s = "hello world"
print(s[4])
print(s[41]) # gives error

Negative Indexing
s = "hello world"
print(s[-3])
print(s[-13]) # gives error

Slicing
s = "hello world"
print(s[6:0:-2])

Example:
print(s[::-1]) # reverse string

s = "hello world"

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
print(s[-1:-6:-1])
Editing and Deleting in Strings
s = "hello world"
s[0] = 'H'

Note: Python strings are immutable


s = "hello world"
del s[-1:-5:2] # cannot delete specific parts of
string
print(s)
s = "hello world"
del s
print(s)

Operations on Strings
 Arithmetic Operations
 Relational Operations
 Logical Operations
 Loops on Strings
 Membership Operations

Example:
print("Pune" + " " + "Mumbai")
print("Pune "*10)
print("*"*50)

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
"Pune" != "Pune"
"Mumbai" > "Pune"
"Pune" > "pune"
"hello" and "world"
"hello" or "world"
"" and "world"
"" or "world"
"hello" or "world"
"hello" and "world"
not "hello"

Example:
for i in "hello":
print(i)

Example:
for i in "Pune":
print("Pune")

Example:
"P" in "Pune"

Common Functions
 len: count length of a string

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
 max: check first string is maximum than second
one or not
 min: check first string is minimum than second or
not
 sorted: sort the characters from given string
 sorted(name,reverse=True): descending order
sorting

Example:
len("hello world")
max("hello world")
min("hello world")
sorted("hello world")
sorted("hello world", reverse = True)

Methods:
Capitalize / Title / Upper / Lower / Swapcase
s = "hello world"
print(s)
print(s.capitalize())
#capitalize only initial letter from given string
s.title()
#capitalize initial letter of every word from a given
string
s.upper()
"HeLlO WorLD".lower()
"HeLlO WorLD".swapcase()

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
#convert capital to lowercase and lowercase to
capital case
Count / Find / Index
"Teknowell EduTech Chinchwad".count("e")
"Teknowell EduTech Chinchwad".find("e")
"Teknowell EduTech Chinchwad".find("z")
"Teknowell EduTech Chinchwad".index("e")
"Teknowell EduTech Chinchwad".index("z")#error code

Note: difference between find and index


If data not found then index gives you value error
But if data not found then find gives you -1 as a
result

endswith / startswith
"Teknowell EduTech Chinchwad".endswith("e")
"Teknowell EduTech Chinchwad".endswith("d")
"Teknowell EduTech Chinchwad".endswith("ech")
"Teknowell EduTech Chinchwad".endswith("wad")
"Teknowell EduTech Chinchwad".startswith("t")
"Teknowell EduTech Chinchwad".startswith("T")
"Teknowell EduTech Chinchwad".startswith("tek")
"Teknowell EduTech Chinchwad".startswith("Tek")

String Format
age=23

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
name="Surekha"
print("My Name is ",name "and age is ",age)#Normal
Way
print(f"My Name is {name} and age is {age}")#using f
print("My name is {0} and age is
{1}".format(name,age))#using format

isalnum / isalpha / isdigit / isidentifier


"Teknowell123".isalnum()
"Teknowell123$".isalnum()
"Teknowell".isalpha()
"Teknowell123".isalpha()
"123".isdigit()
"123abc".isdigit()
"first_name".isidentifier()
"first-name".isidentifier()

Split: convert string to array


"Teknowell EduTech Chinchwad".split()

Join: convert array to string


" ".join(['Teknowell', 'EduTech', 'Chinchwad'])

Replace
"Teknowell EduTech Chinchwad".replace("Chinchwad",
"Pimpri")

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
"Teknowell EduTech Chinchwad".replace("akgjhl",
"Pimpri")

Strip: remove left and right side spaces


name="teknowell "
print(len(name))
print(name)
print(name.strip())#remove left and right spaces
print(len(name.strip()))

Example Programs
Find the length of a given string without using the
len() function
s = input("Enter a string: ")
counter = 0
for i in s:
counter += 1
print("Length of given string is =", counter)

Extract username from a given email.


Example, if the email
is [email protected] then the username
should be teknowell123edutech
mail=input('Enter mail id:')
pos=mail.find('@')
print(mail[:pos])

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
Count the frequency of a particular character in
provided string.
Example, "hello how are you" is a string, the
frequency of h in this string is 2.
Using function:
sentence=input('Enter any sentence:')
word=input('Enter any word:')
count=sentence.count(word)
print(count)

Without using function(count)


s = input("Enter String : ")
term = input("What would like to search for? ")
counter = 0
for i in s:
if i == term:
counter += 1
print("Frequency of {} in {} is ".format(term, s) ,
counter)

Write a program which can remove a particular


character from a string.
s = input("Enter a string : ")
term = input("what would like to remove : ")
result = ""
for i in s:
if i != term:

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
result = result + i
print(result)

Write a program that can check whether a given string


is palindrome or not.
Check for:
 noon
 malayalam
 python
s = input("Enter a string : ")
flag = True
for i in range(0, len(s)//2):
if s[i] != s[len(s) - i - 1]:
flag = False
print("Not Palindrome")
break
if flag:
print("Palindrome")

Write a program to count the number of words in a


string without split()
s = input("Enter a string : ")
L = []
temp = ""
for i in s:
if i != " ":

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
temp += i
else:
L.append(temp)
temp = ""
L.append(temp)
print("Splited string :", L)
print("Number of words in given string is :", len(L))

Write a python program to convert a string to title


case without using the title() function
s = input("Enter a string : ")
L = []
for i in s.split():
L.append(i[0].upper() + i[1:].lower())
print(" ".join(L))

Write a program that can convert an integer to


string.
number = int(input("Enter a number : "))
print(type(number))
digits = "0123456789"
result = ""
while number != 0:
result = digits[number % 10] + result
number = number//10
print("\nString Integer :", result)

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
print(type(result))

Time Complexity:
Techniques to measure time complexity
 Measuring Time to execute
 Counting operations involved
 Abstract notion of order of growth

Measuring Time to Execute:


import time
start=time.time()
for i in range(1,100):
print(i)
end=time.time()
print(end-start)

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
What is the meaning of Time varies if implementation
changes use the below code:
Here instead of for I’m using while see the time is
different.
import time
start=time.time()
i=1
while(i<=100):
i=i+1
end=time.time()
print(end-start)

Counting operations involved

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
What do we want?
1.We want to evaluate the algorithm
2.We want to evaluate scalability(how it behaves
for big inputs)
3.We want to evaluate in terms of input size(built
the mathematical relationship between the input
and time taken by the program)

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
Orders of Growth(This technique mostly used in
industry)

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
In above
answer=1 is first operation----------it is outside of
loop

answer*=n makes two operations


n-=1 makes two operations
n>1 it makes 1 operations

return answer makes 1 operation----------it is also


outside of loop

So, Count:1+5n+1--------5n+2
Five operations performs multiple times
Ignore additive constant that is 2

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
Ignore multiplicative constant that is 5.
So,
Time complexity of above program is O(n).

Output-1:

Output-2:

Output-3:

Output-4:

Output-5:

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
Constant:

If input increases still time required to fetch 35th


position data is same.
Linear:O(n)
Searching data from database.

Quadratic:O(n^2)
Nested loop

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
Logarithmic:(n)
Increase input time decreases.

Example:
Binary search

O(n log n):


All sorting algorithms.

Exponential:(O(2^n)):
Input increase time also increases but its in a high
amount.

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
If both the for loops are same then use below

If second for loop is bigger then use below

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
Example:
number = int(input('enter the number'))

digits = '0123456789'
result = ''
while number != 0:
result = digits[number % 10] + result
number = number//10

print(result)

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
Example:
L = [1,2,3,4]

sum = 0
for i in L:
sum = sum + i

product = 1
for i in L:
product = product*i

print(sum,product)

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
Example:
A = [1,2,3,4]
B = [5,6,7,8]
for i in A:
for j in B:
print(i,j)

In above both loops are dependent, so do the


multiplication

Example:
A = [1,2,3,4]
B = [5,6,7,8]
Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
for i in A:
for j in B:
for k in range(1000000):
print(i,j)

Example:
L = [1,2,3,4,5]

for i in range(0,len(L)//2):
other = len(L) - i -1
temp = L[i]
L[i] = L[other]
L[other] = temp

print(L)

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
Here number of operations are 4.
len(L)/2
n/2

Example:
n = 10
k = 0;
for i in range(n//2,n):
for j in range(2,n,pow(2,j)):
k = k + n / 2;

print(k)

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
Example:
a = 10
b = 3

if b <= 0:
print(-1)
div = a//b

print(a-div-b)

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
Example:
n = 345

sum = 0
while n>0:
sum = sum + n%10
n = n // 10

print(sum)

Example:
def fib(n):
Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
if n == 1 or n == 0:
return 1
else:
return fib(n-1) + fib(n-2)

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
Example:Subset Algo

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
Example:
{3T(n-1) if n>0
T(n) = {1, otherwise

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
Example:
{2T(n-1)-1 if n>0
T(n) = {1, otherwise

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
Week-1 Interview Questions
1.What is Python? What are the benefits of using
Python?
2.What is a dynamically typed language?
3.What is an Interpreted language?
4.What is PEP 8 and why is it important?
5.What are the common built-in data types in
Python?
6.Explain the ternary operator in Python.
7.What Does the ‘is’ Operator Do?
8.Disadvantages of Python.
9.How strings are stored in Python?
10.What is Zen of Python?

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
11.Identity operator (is) vs ==?
12.What does _ variables represent in Python?
13.Modules vs packages vs Library
14.Why 0.3 – 0.2 is not equal to 0.1 in Python?
15.Python Docstrings

1. What is Python? What are the benefits of using


Python?
Python is a high-level, interpreted, general-purpose
programming language. Being a general-purpose
language, it can be used to build almost any type of
application with the right tools/libraries.
Additionally, python supports objects, modules,
threads, exception-handling, and automatic memory
management which help in modelling real-world
problems and building applications to solve these
problems.

Benefits of using Python:


- Python is a general-purpose programming language
that has a simple, easy-to-learn syntax that
emphasizes readability and therefore reduces the cost
of program maintenance. Moreover, the language is
capable of scripting, is completely open-source, and
supports third-party packages encouraging modularity
and code reuse.
- Its high-level data structures, combined with
dynamic typing and dynamic binding, attract a huge
community of developers for Rapid Application
Development and deployment.

2. What is a dynamically typed language?

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
Before we understand a dynamically typed language, we
should learn about what typing is. **Typing** refers
to type-checking in programming languages. In a
**strongly-typed** language, such as Python, **"1" +
2** will result in a type error since these languages
don't allow for "type-coercion" (implicit conversion
of data types). On the other hand, a **weakly-typed**
language, such as Javascript, will simply output
**"12"** as result.

Type-checking can be done at two stages:


Static - Data Types are checked before execution.
Dynamic - Data Types are checked during execution.
Python is an interpreted language, executes each
statement line by line and thus type-checking is done
on the fly, during execution. Hence, Python is a
Dynamically Typed Language.

Read more -
https://www.techtarget.com/whatis/definition/strongly
-typed#:~:text=In%20computer%20programming%2C%20a
%20programming,types%20of%20objects%20and
%20variables.

3. What is an Interpreted language?


An Interpreted language executes its statements line
by line. Languages such as Python, Javascript, R,
PHP, and Ruby are prime examples of Interpreted
languages. Programs written in an interpreted
language runs directly from the source code, with no
intermediary compilation step.

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
4. What is PEP 8 and why is it important?
PEP stands for Python Enhancement Proposal. A PEP is
an official design document providing information to
the Python community, or describing a new feature for
Python or its processes. **PEP 8** is especially
important since it documents the style guidelines for
Python Code. Apparently contributing to the Python
open-source community requires you to follow these
style guidelines sincerely and strictly.

Read more -
https://realpython.com/python-pep8/#:~:text=PEP
%208%2C%20sometimes%20spelled%20PEP8,and
%20consistency%20of%20Python%20code.

5. What are the common built-in data types in Python?


There are several built-in data types in Python.
Although, Python doesn't require data types to be
defined explicitly during variable declarations type
errors are likely to occur if the knowledge of data
types and their compatibility with each other are
neglected. Python provides “type()” and
“isinstance()” functions to check the type of these
variables. These data types can be grouped into the
following categories-

1. None Type:None keywork represents the null values


in Python. Boolean equality operation can be
performed using these NoneType objects.

2. Numeric Type: There are three distinct numeric


types - integers, floating-point numbers and complex

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
numbers. Additionally, booleans are a sub-type of
integers.

3. Sequence Types: According to Python Docs, there


are three basic Sequence Types - lists, tuples, and
range objects. Sequence types have the in and not in
operators defined for their traversing their
elements. These operators share the same priority as
the comparison operations.

4. Mapping Types: A mapping object can map hashable


values to random objects in Python. Mappings objects
are mutable and there is currently only one standard
mapping type, the dictionary.

5. Set Types: Currently, Python has two built-in set


types - set and frozenset. set type is mutable and
supports methods like add() and remove(). frozenset
type is immutable and can't be modified after
creation.

6. Callable Types:Callable types are the types to


which function call can be applied. They can be user-
defined functions, instance methods, generator
functions, and some other built-in functions, methods
and classes.
Refer to the documentation at [docs.python.org]
(https://docs.python.org/3/reference/datamodel.html)
for a detailed view of the callable types.

Q.6. Operator Precedence.

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
https://www.programiz.com/python-programming/
precedence-associativity

Q.7. Explain the ternary operator in Python.

Unlike C++, we don’t have ?: in Python, but we have


this:

> [on true] if [expression] else [on false]

If the expression is True, the statement under [on


true] is executed. Else, that under [on false] is
executed.

Below is how you would use it:

a,b=2,3
min=a if a<b else b
print(min)

Above will print 2.

Q 8. What Does the ‘is’ Operator Do?

Identity operators<br>
In Python, is and is not are used to check if two
values are located on the same part of the memory.
Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
Two variables that are equal does not imply that they
are identical.

a is b

id(a)

id(b)

a = 257
b = 257

a is b

id(a)

a == b

id(b)

# -5 to 256 till data it store data on different


address

a = -14
b = -14

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
a is b

Q 9: Disadvantages of Python.

https://www.geeksforgeeks.org/disadvantages-of-python

Q10 How strings are stored in Python?


- https://stackoverflow.com/questions/19224059/how-
strings-are-stored-in-python-memory-model
- https://www.quora.com/How-are-strings-stored-
internally-in-Python-3
- https://betterprogramming.pub/an-interviewers-
favorite-question-how-are-python-strings-stored-in-
internal-memory-ac0eaef9d9c2

Q11 What is Zen of Python?

The Zen of Python is a collection of 19 "guiding


principles" for writing computer programs that
influence the design of the Python programming
language.
https://en.wikipedia.org/wiki/Zen_of_Python

* 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.

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
* 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!

Explained in detail here -


https://inventwithpython.com/blog/2018/08/17/the-zen-
of-python-explained/

Q12 Identity operator (is) vs ==?

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
->> Here’s the main difference between python “==” vs
“is:”

Identity operators: The “is” and “is not” keywords


are called identity operators that compare objects
based on their identity.
Equality operator: The “==” and “!=” are called
equality operators that compare the objects based on
their values.

# Case 4:
# Here variable s is assigned a list,
# and q assigned a list values same as s but on
slicing of list a new list is generated
s=[1,2,3]
p=s
# cloning:
q=s[:]#-this is called as cloning means store data on
different location
print("id of p", id(p))
print("Id of s", id(s))
print("id of q", id(q))
print("Comapare- s == q", s==q)
print("Identity- s is q", s is q)
print("Identity- s is p", s is p)
print("Comapare- s == p", s==p)

#Why we need cloning:

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
a=[1,2,3]
b=a
a.append(4)
print(a)
print(b)

a = [1,2,3]
b = a[:]#this is called as cloning means store data
on different location

a.append(4)
print(a)
print(b)

Q13 What does _ variables represent in Python?

[GssksForGeeks
Article](https://www.geeksforgeeks.org/underscore-_-
python)

Underscore _ is considered as "I don't Care" or


"Throwaway" variable in Python

The underscore _ is used for ignoring the specific


values. If you don’t need the specific values or the
values are not used, just assign the values to
underscore.

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
Ignore a value when unpacking

Ignore the index

# Ignore a value when unpacking


x, _, y = (1, 2, 3)

print("x-",x)
print("y-", y)

Ignore the index

Say we want to print hello 5 times, we don't need


index value

for _ in range(5):
print('hello')

Q14 Modules vs packages vs Library

Python uses some terms that you may not be familiar


with if you’re coming from a different language.
Among these are modules, packages, and libraries.

* A module is a Python file that’s intended to be


imported into scripts or other modules. It often
defines members like classes, functions, and
Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
variables intended to be used in other files that
import it.

* A package is a collection of related modules that


work together to provide certain functionality. These
modules are contained within a folder and can be
imported just like any other modules. This folder
will often contain a special `__init__` file that
tells Python it’s a package, potentially containing
more modules nested within subfolders

* A library is an umbrella term that loosely means “a


bundle of code.” These can have tens or even hundreds
of individual modules that can provide a wide range
of functionality. Matplotlib is a plotting library.
The Python Standard Library contains hundreds of
modules for performing common tasks, like sending
emails or reading JSON data. What’s special about the
Standard Library is that it comes bundled with your
installation of Python, so you can use its modules
without having to download them from anywhere.

These are not strict definitions. Many people feel


these terms are somewhat open to interpretation.
Script and module are terms that you may hear used
interchangeably.

https://stackoverflow.com/questions/19198166/whats-
the-difference-between-a-module-and-a-library-in-
python

https://www.geeksforgeeks.org/what-is-the-difference-
between-pythons-module-package-and-library/
Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
Q15 Why 0.3 – 0.2 is not equal to 0.1 in Python?

The reason behind it is called “*precision*”, and


it’s due to the fact that computers do not compute in
Decimal, but in Binary. Computers do not use a base
10 system, they use a base 2 system (also called
Binary code).

https://www.geeksforgeeks.org/why-0-3-0-2-is-not-
equal-to-0-1-in-python/

# code
print(0.3 - 0.2)
print(0.3 - 0.2 == 0.1)

Q 16 - Python Docstrings

https://www.geeksforgeeks.org/python-docstrings

print('hello')

type(3)

print(input.__doc__)#it means it gives explaination


related what is the use of input

print(type.__doc__)
Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.
~(3)

s="have"
print(s)
s.capitalize()#changes not done in original, it
creates new string
print(s)

s = 'have'
print(id(s))
s = s.capitalize()
print(id(s))

print('hello'),print('world')

a,b = print('hello'),print('world')

print(a,b)

for i in range(1, 5):


i = 3
print(i, end=' ')

Office No-77,5th Floor, Kunal Plaza, Old Mumbai-Pune Highway, Chinchwad, Pune.

You might also like