Skip to content

Commit b2e11e3

Browse files
authored
Merge pull request #2 from TechPrimers/learn/functions
Learn/functions
2 parents b4b87b3 + 49751d2 commit b2e11e3

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

functions.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Functions:
2+
3+
def __init__(self):
4+
self._cache = []
5+
6+
def __call__(self, name):
7+
if name not in self._cache:
8+
self._cache.append(name)
9+
return self._cache

functions_main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from functions import Functions
2+
func = Functions()
3+
print(func("ajay"))
4+
print(func("jaga"))

strings.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Strings are immutable. None of the changes affect the original variable unless assigned
2+
import string
3+
4+
extractor="Hello World"
5+
print("Full String: ", extractor[:])
6+
7+
print("Offset from 3: ", extractor[3:])
8+
print("Offset from :3 ", extractor[:3])
9+
print("Offset from 3:8 ", extractor[3:8])
10+
11+
print("Last 3 characters: ", extractor[-3:])
12+
print("Last 3 characters: ", extractor[4:-3])
13+
14+
print("By space: ", extractor.split(" "))
15+
16+
strip_variable = "This has punctuations ..!!"
17+
print("Strip Punctuations: ", strip_variable.strip(string.punctuation))
18+
print("Strip White spaces: ", strip_variable.strip(string.whitespace))
19+
print("Strip Punctuations and White spaces: ", strip_variable.strip(string.whitespace + string.punctuation))
20+
21+
print("Find the: ", strip_variable.find("the"))
22+
print("rFind the: ", strip_variable.rfind("the"))
23+
print("Find has: ", strip_variable.find("has"))
24+
25+
# Returns substring not found error unlike -1 in find
26+
# print("Index the: ", strip_variable.index("the"))
27+
# print("rIndex the: ", strip_variable.rindex("the"))
28+
29+
30+
count_variable = "This has repeated texts for counting texts"
31+
print("Count: ", count_variable.count("text"))
32+
33+
alpha_variable = "Thishasnumbersandtexts2"
34+
print("alpha_variable isAlphanumberic: ", alpha_variable.isalnum())
35+
print("count_variable isAlphanumberic: ", count_variable.isalnum())
36+
37+
title = "This is a title"
38+
print("Title: ", title.title())

0 commit comments

Comments
 (0)