Skip to content

Commit b8f732e

Browse files
added basic syntax, data types, strings, lists
1 parent a1b44ce commit b8f732e

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed

basic_syntax.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# "#" is used for single line comments
2+
3+
'''
4+
used to write multiline comment
5+
this is a multiline comment
6+
7+
'''
8+
9+
# basic print statement
10+
print ("Hello Codex!") #printing a string
11+
print (25) #printing a integer
12+
print (50.2) #printing a decimal
13+
14+
15+
# taking input and store it in variable
16+
var1 = int(input("Enter the number"))
17+
print (var1)
18+
19+
var2 = input ("Enter the string")
20+
print (var2)
21+
22+
var3 = float(input("Enter a decimal value"))
23+
print (var3)

data_types.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'''
2+
There are mainly 5 categories of data type: Numbers, Strings, Lists, Tuples, Dictionaries
3+
'''
4+
5+
#assigning value to variables
6+
7+
x = 25 # integer type
8+
y = 50.25 # floating type
9+
name = "codex" # string type
10+
11+
print (x)
12+
print (y)
13+
print (name)
14+
15+
# to know which data type the variables are use predefined function type()
16+
# print (type(variable_name))
17+
18+
print ("variable x is",type(x))
19+
print ("variable y is",type(y))
20+
print ("variable name is",type(name))

lists.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Diving into lists
2+
3+
#initializing a empty list
4+
l1 = []
5+
print (l1)
6+
7+
l2 = [1,2,3,4,5] # list with number datatype
8+
l3 = ["codex" , "iter" , "python"] # list with string datatype
9+
l4 = ["codex" , 25 , 50.25 , "iter"] # list with different datatype
10+
11+
print (l2)
12+
print (l3)
13+
print (l4)
14+
15+
16+
# updating value of lists
17+
list = [10 , 20 , 30 , 40 , 50]
18+
print ("Before Updation: \n",list)
19+
list[2] = 100 # the 2nd index i.e, 3rd element of the list will beupdated to 100
20+
print ("After updation: \n",list)
21+
del( list[2]) #deletes the 2nd index, i.e, the 3rd element of the list
22+
print("After deleting: \n",list)
23+
list.append(60) #add the value 60 at the end of the list
24+
print("After appending list:\n",list)
25+
26+
27+
# printing lists
28+
print (list) #prints the whole list
29+
print (list[2]) #prints the 2nd index ,i.e, the 3rd element of the list
30+
print (list[1:3]) #prints the list value from 2nd value to 4th
31+
print (list[::-1]) #prints the list in reverse order
32+
print (list[-1]) #prints the last element when the index goes -ve. it will go from backward
33+

strings.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Diving into string type data type
2+
name = "CODEX"
3+
print (name) # prints the whole string
4+
print (name[1]) # prints the character os specific index, here "O"
5+
print (name[1:3]) # prints the string from 1st index to 3rd i.e, 2nd character to 4th
6+
print (name[1:]) # prints the whole string from 1st index i.e, 2nd character to last
7+
print (name*2) # prints the string 2 times
8+
print (name + " ITER") # prints the string along with the added string
9+
print (name[::-1]) # prints the string in reversed order
10+
print ("The String is",name,"ITER") #printing the string along with other string
11+
12+
# printing sentences
13+
# '\t' : to give tabs
14+
# '\n' : next line
15+
long_string = "\n\nLorem \t ipsum \t dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. \n Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\n Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
16+
print (long_string)
17+
18+
#another way to write long paragraphs in multi line
19+
long_string = """\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
20+
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
21+
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n\n"""
22+
print (long_string)
23+
24+
25+
# some other useful built-in string methods
26+
print (name.capitalize()) # capitalizes first letter of string
27+
print (name.upper()) # converts all lowercase letters in string to uppercase
28+
print (name.lower()) # converts all uppercase letters in string to lowercase
29+
print (len(name)) # prints the length of the string
30+

0 commit comments

Comments
 (0)