Home Python Scripting
Post
Cancel

Python Scripting

Code block


1
2
print ("welcome to Python")

1
welcome to Python
1
print("Python indentations")
1
Python indentations
1
2
3
print("Python indentations")
print("")
print("#######")
1
2
3
Python indentations

#######
1
2
#This is comment, single line
print("$$$$$$$$$$$$$$")
1
$$$$$$$$$$$$$$
1
2
3
4
5
"""This
is a
multi line
comment"""
print("&&&&&&&&&&")
1
&&&&&&&&&&
1
2
3
4
5
'''
This is
a multi line
comment'''
print("$$$$$$$$$$$$")
1
$$$$$$$$$$$$
1
2
3
4
Name='python'
print("Name")
print(Name)
print('Name')
1
2
3
Name
python
Name
1
2
3
4
Name=Python
Python='Python'
print("This is a string.")
print('This is a string.')
1
2
This is a string.
This is a string.

Python=’Python’ print(“This is a”,Python)

1
2
print("Kumar raj luckynumber is",7)

1
Kumar raj luckynumber is 7
1
2
3
4
5
6
#Paragraph string
print("""This
is
a
multi line
string print""")
1
2
3
4
5
This
is
a
multi line
string print
1
2
3
4
5
a = 'alpha'
b = "beta"
c = """theta"""

print("a for",a,"\nb for",b,"\nc for",c)
1
2
3
a for alpha
b for beta
c for theta
1
print(type(a))
1
<class 'str'>
1
2
3
4
5
6
7
#Numbers
#Integer

x = 12
y = 6.7

print(x,y)
1
12 6.7
1
2
3
4
5
6
7
#List, collection of multi datatypes, enclosed in []. This
# datatypes can be changeable(MUTABLE)

list1 = [a, b, c, "Devops", 89, 90.245]


print(list1)
1
['alpha', 'beta', 'theta', 'Devops', 89, 90.245]
1
2
3
4
5
6
#Tuple, collection of multi datatypes, enclosed in {}. This
# datatypes can be changeable(IMMUTABLE)

tuple1 = {a, b, c, "Devops", 89, 90.245}

print(tuple1)
1
{'theta', 'Devops', 'beta', 89, 90.245, 'alpha'}
1
2
3
4
5
6
#Dictionary, collection of elements in pair(key:value), enclosed inside {}

my_dictionary = {"Name":"Kumar Raj","Age":21,"Weight":54,"Hobbies":["Reading","Listening to Music"]}


print(my_dictionary)
1
{'Name': 'Kumar Raj', 'Age': 21, 'Weight': 54, 'Hobbies': ['Reading', 'Listening to Music']}
1
2
3
4
5
###SLICING

message = "Virus new variant is deltacron"

print(message)
1
Virus new variant is deltacron
1
2
3
4
print(message[0])
print(message[3])
print(message[-4])
print(message[-1+1])
1
2
3
4
V
u
c
V
1
2
#string slicing
print(message[6:10])
1
new
1
print(message[10:17])
1
variant
1
print(message[-9:])
1
deltacron
1
print(message[:5])
1
Virus
1
2
3
#List Slicing

animals=["snake", "Honeybadger", "Trex", "Leopard", "Cheetah", "Elephant", "crocodile"]
1
print(animals)
1
['snake', 'Honeybadger', 'Trex', 'Leopard', 'Cheetah', 'Elephant', 'crocodile']
1
2
3
4
print(animals[1])
print(animals[2:5])
print(animals[:4])
print(animals[-3:])
1
2
3
4
Honeybadger
['Trex', 'Leopard', 'Cheetah']
['snake', 'Honeybadger', 'Trex', 'Leopard']
['Cheetah', 'Elephant', 'crocodile']
1
print(animals[2:5])
1
['Trex', 'Leopard', 'Cheetah']
1
print(animals[2:5][-2])
1
Leopard
1
print(animals[2:5][-2][:3])
1
Leo
1
print(animals[2:5][-2][:3][-1])
1
o
1
2
3
4
#Slicing Dictionary

my_dictionary= {"Name":"Imran", "Age": 24, "Weight": 73.5, "Hobbies":["Dance", "Boxing", "Swimming"]}
print(my_dictionary)
1
{'Name': 'Imran', 'Age': 24, 'Weight': 73.5, 'Hobbies': ['Dance', 'Boxing', 'Swimming']}
1
print(my_dictionary["Name"])
1
Imran
1
print(my_dictionary["Hobbies"][-1])
1
Swimming
1
print(my_dictionary["Hobbies"][-1][4:])
1
ming
1
This post is licensed under CC BY 4.0 by the author.