What is String?
->String is immutalble.
->All the languages string is spcial method.
->String in python are surrounded by either single qutation marks, or double qutation marks.
-> In Python more string methods are available.
-> String are commonly used for text handling and manipulation.
Immutable:
->Existing Memory wont get affected. Instead, change will be updated in new memory.
Mutable:
->A mutable value is one that can be changed without creating an entirely new value, in comparison with immutable values.
name = "Muthukumarasamy" #String
print(type(name)) # its print only the which type <class 'str'>
print(id(name)) # its print memory allocation ID
Output:
<class 'str'>
2702430470704
Garbage Collector:
->Unsed memory objects.
->Garbage Collection in Python is an automatic process that handles memory allocation and deallocation, ensuring efficient use of memory.
->In python method gc in this method import th python file
-> Garbage collection mostly used for the OTP verfication.
-> More methods are available.
-> Commomly uesed method are:
gc.enable()
Enable automatic garbage collection.
gc.disable()
Disable automatic garbage collection
gc.isenabled()
Return True if automatic collection is enabled.
name = "Muthukumarasamy"
print(id(name)) # its unused memory its called by the garbage collection old memory: 2639045886512
name = "T Muthukumarsamy"
print(id(name)) # new Memory allocation its a string new memory allocation: 2639045890608
String Length:
name = "MuthuKumarasamy"
print(len(name)) # string length calculator
i = 0
while i<len(name):
print(name[i],end = ' ')
i+=1
Method overload:
->The @overload decorator allows describing functions and methods that support multiple different combinations of argument types.
->This pattern is used frequently in builtin modules and types.
Examble:
print('spam, spam, spam'.find('sp'))
print('spam, sdam, spam'.find('sp', 5))
class calculater:
def add (self, a , b=0):
return a+b
calc = calculater()
print(calc.add(5))
print(calc.add(5,10))
Top comments (0)