Skip to content
This repository was archived by the owner on Nov 17, 2025. It is now read-only.

Commit 8d9e244

Browse files
author
Kalpak Take
authored
Add files via upload
1 parent a713f32 commit 8d9e244

File tree

5 files changed

+156
-0
lines changed

5 files changed

+156
-0
lines changed

listOperations.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# list operations
2+
# You can create a list by putting elements inside square brackets[]
3+
# lists are capable of containing any type of data
4+
5+
# a list can contain datas of different datatypes
6+
numsAndAlphas = ['a',1,'hello',3.14159265359,'are you okay',True,'good',False]
7+
# this is going to work
8+
print(numsAndAlphas)
9+
10+
# list accessing
11+
# You can access single items from the list similar to string indexing
12+
# if you dont know string indexing look for my program called stringOperations.py
13+
print(numsAndAlphas[0])
14+
print(numsAndAlphas[1:5])
15+
print(numsAndAlphas[0:])
16+
print(numsAndAlphas[:6])
17+
print(numsAndAlphas[:])
18+
print(numsAndAlphas[2:7:2])
19+
print(numsAndAlphas[::3])
20+
21+
# you can add lists too...
22+
list2 = [2,9,16,25,36,49,64,81,100,144]
23+
newList = numsAndAlphas + list2

listOperationsMethods.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# list operations part 2
2+
3+
siliconValley = ['Google','Apple','Dropbox','Facebook','Cisco','Adobe','Oracle','Samsung']
4+
print(siliconValley)
5+
6+
# hmm seems like i forgot to add Electronic Arts in the list siliconValley
7+
# This will add the element at the end of the list
8+
siliconValley.append('Electronic Arts')
9+
print(siliconValley)
10+
11+
# thats cool but I want my element at specific position
12+
siliconValley.insert(5, 'AMD')
13+
# 5 is the position and whatever you add after comma is element
14+
15+
# Okay enough I want to pop out an element from list and I want to use it in a string
16+
# you have to provide the index of elementyou want to pop out
17+
poppedElement = siliconValley.pop(4)
18+
print('Popped element is ' + poppedElement)
19+
20+
# Oops I Samsung isnt in silicon valley, I have to remove Samsung from list
21+
# How am I gonna do thats
22+
# You have to enter the element in parenthesis and not it's index
23+
siliconValley.remove('Samsung')
24+
print(siliconValley)
25+
26+
# I want to sort the list in alphabetical order
27+
# How to do thats
28+
# simple
29+
siliconValley.sort()
30+
# or
31+
sorted(siliconValley)
32+
print(siliconValley)
33+
34+
# I wanted list in reverse alphabetical order
35+
# simple
36+
siliconValley.sort(reverse = True)
37+
# or
38+
sorted(siliconValley , reverse = True) # seperate the reverse with comma
39+
print(siliconValley)
40+
41+
# I am tired of watching those elements again and again
42+
# How I am going to do thats
43+
# easy
44+
del siliconValley
45+
print(siliconValley) # this should probably give you an NameError

mathoperators.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# maths sucks make it cool with python
2+
# math operators
3+
4+
# INTEGERS
5+
# integers are whole numbers positive or negative
6+
# + operator adds numbers
7+
add = 24 + 1004
8+
# - operator subtracts second number from First
9+
subtract = 546 - 132
10+
# * multiplies numbers
11+
multiply = 90 * 4
12+
# / divides numbers
13+
divide = 36/6
14+
# returns the remainder of the division
15+
modulo = 17 % 3
16+
17+
# FLOAT
18+
# floats are decimal point numbers positive or negative
19+
addFloat = 24.5 + 1004.005
20+
subtractFloat = 546.90 - 132.56
21+
multiplyFloat = 90.0 * 4.2
22+
divideFloat = 36.6 / 6.6
23+
moduloFloat = 17.0 % 3.0
24+
25+
# all operators work same on both floats or integers

stringIndexing.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# string indexing
2+
3+
'''
4+
Indexing
5+
0 1 2 3 4
6+
H E L L O
7+
'''
8+
9+
message = 'Hello'
10+
print(message[0]) # this will print H that is first letter in the string
11+
print(message[1:4]) # this will print from index one to index four
12+
print(message[:3]) # this will print from starting to index 3
13+
print(message[2:]) # this will print from index 2 till end
14+
print(message[:]) # this prints whole string
15+
print(message[0:4:2]) # this escapes 2 characters from string
16+
17+
# negative Indexing
18+
'''
19+
negative Indexing
20+
P y t h o n
21+
-6 -5 -4 -3 -2 -1
22+
'''
23+
24+
awesome = 'Python is awesome'
25+
print(awesome[:-1]) # -1 prints last character
26+
print(awesome[-2]) # this prints m from starting
27+
print(awesome[-7:]) # try this one out in interpreter
28+
29+
print('You are ' + awesome[10:] + ' you are learning ' + awesome[:6])

stringOperations.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# This example shows you string operations
2+
3+
name = 'Kalpak'
4+
print('My name is ' + name) # I have given space after is notice
5+
6+
age = 14
7+
print('My age is ', age) # comma seprates two different things you want to print
8+
9+
print('This isn\'t going away too soon.') # that \ is called as an escape character
10+
# the \ is used to use same quote in a string
11+
12+
print('I love newlines \n') # \n prints new line after string or according to its position
13+
14+
print('\t I love tabs') # \t adds a tab according to its position
15+
16+
multiple = 'Iron Man'
17+
print(multiple * 5) # this will print string 5 times
18+
19+
# string methods in built
20+
country = 'Norway'
21+
print(country.upper()) # prints all letters in upper case
22+
print(country.lower()) # prints all letters in lower case
23+
print(country.title()) # converts into title
24+
25+
# string formatting
26+
print('%s %s %s'%('I' , 'am' , 'cool'))
27+
28+
expression = 'I love'
29+
movie = 'Captain America 3'
30+
print('%s %s'%(expression , movie))
31+
32+
# type conversion
33+
addition = 12343 + 3349
34+
print('The answer is ' + str(addition)) # str() method converts non-string into string

0 commit comments

Comments
 (0)