Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e2bc030

Browse files
Python for Beginners
1 parent 36a1ce7 commit e2bc030

File tree

5 files changed

+109
-0
lines changed

5 files changed

+109
-0
lines changed

‎beginners/dictionary_key_value.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
""" This file is create and managed by Tahir Iqbal
2+
----------------------------------------------
3+
It can be use only for education purpose
4+
"""
5+
6+
dict = {'a': 1, 'b': 2, 'c': 3, 'd': 4}
7+
print("Keys and its Values")
8+
for key, value in dict.items():
9+
# .items() prints both keys and values
10+
print(key, value, sep='->')
11+
12+
13+
# print only keys nor values
14+
print("\nKeys of Dictionary")
15+
for key in dict:
16+
print(key)
17+
18+
# print only values
19+
print("\nValues of Dictionary")
20+
for value in dict.values():
21+
print(value)

‎beginners/list_sorting.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
""" This file is create and managed by Tahir Iqbal
2+
----------------------------------------------
3+
It can be use only for education purpose
4+
"""
5+
6+
# Sorting List
7+
developer = ['Web', 'Software', 'Data Science', 'Application']
8+
print(developer)
9+
developer.sort() # sort ascending, now list change into ascending
10+
print(developer)
11+
developer.sort(reverse=True) # sort descending, now list change into descending
12+
print(developer)
13+
14+
developer = ['Web', 'Application']
15+
print(sorted(developer)) # doesn't affect or change original list
16+
print(developer)

‎beginners/removing_white_spaces.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
""" This file is create and managed by Tahir Iqbal
2+
----------------------------------------------
3+
It can be use only for education purpose
4+
"""
5+
6+
# Whitespace
7+
name = " Tahir Iqbal "
8+
print('_' + name + '_')
9+
10+
# removes left side spaces
11+
print('_' + name.lstrip() + '_')
12+
13+
# removes right side spaces
14+
print('_' + name.rstrip() + '_')
15+
16+
# removes all spaces from left and right both sides
17+
print('_' + name.strip() + '_')
18+
19+
# also use lstrip and rstrip at same time instead of strip
20+
print("\nlstrip() and rstrip() at same time")
21+
print('_' + name.lstrip().rstrip() + '_')

‎beginners/sets_and_operators.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
""" This file is create and managed by Tahir Iqbal
2+
----------------------------------------------
3+
It can be use only for education purpose
4+
"""
5+
6+
# Set & Set Operations
7+
num_set = {2, 3, 4, 6} # set() is known empty set
8+
print(num_set)
9+
10+
# Adding items in set
11+
num_set.add(1)
12+
num_set.add(5)
13+
14+
# Remove item from set
15+
num_set.remove(6)
16+
print(num_set)
17+
print('\n\n')
18+
19+
# Set Operations
20+
set_a = {1, 2, 3, 4, 5}
21+
set_b = {4, 5, 6, 7, 8}
22+
print('Set A : ', set_a)
23+
print('Set B : ', set_b)
24+
25+
print('Set A | Set B : ', set_a | set_b) # union set, print all value set a and b which value is two times they print once
26+
print('Set A & Set B : ', set_a & set_b) # intersection set, print value which is in both of set a and b
27+
print('Set A - Set B : ', set_a - set_b) # difference set, remove set b value from a then prints remaining values of a
28+
print('Set A ^ Set B : ', set_a ^ set_b) # symmetric difference, print set a and b items which does'nt matches
29+

‎beginners/single_double_quotes.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
""" This file is create and managed by Tahir Iqbal
2+
----------------------------------------------
3+
It can be use only for education purpose
4+
"""
5+
6+
# Printing Single and Double Quote
7+
8+
# single quote should print in double quotes
9+
single = "Python's"
10+
print(single)
11+
12+
# double quote should print in single quotes
13+
double = 'Python"s'
14+
print(double)
15+
16+
# single quote prints in single quotes use \ sign
17+
singles = 'Python\'s'
18+
print(singles)
19+
20+
# double quote prints in double quotes use \ sign
21+
doubles = "Python\"s"
22+
print(doubles)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /