0% found this document useful (0 votes)
13 views8 pages

Python Data Types and Operations

The document contains a series of Python code snippets demonstrating variable types, arithmetic operations, string manipulations, list and tuple operations, and dictionary usage. It includes examples of input, type checking, and basic data structures. The code illustrates how to manipulate and format strings, perform calculations, and work with collections in Python.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views8 pages

Python Data Types and Operations

The document contains a series of Python code snippets demonstrating variable types, arithmetic operations, string manipulations, list and tuple operations, and dictionary usage. It includes examples of input, type checking, and basic data structures. The code illustrates how to manipulate and format strings, perform calculations, and work with collections in Python.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

zcxvpo5i0

January 21, 2025

[1]: name = "xyz"


a = 12
b = 3.25

[2]: print(type(name))
print(type(a))
print(type(b))

<class 'str'>
<class 'int'>
<class 'float'>

[50]: my_text = input("enter your name:" )

enter your name: xyza

[5]: print(my_text)

Kirti

[7]: x = True
print(type(x))

<class 'bool'>

[8]: a+b

[8]: 15.25

[9]: a-b

[9]: 8.75

[10]: a*b

[10]: 39.0

[11]: a/b

1
[11]: 3.6923076923076925

[12]: a//b

[12]: 3.0

[13]: a%b

[13]: 2.25

[14]: a**b

[14]: 3216.170393056856

[16]: print(len(my_text))

[17]: my_text[1]

[17]: 'i'

[18]: my_text[-1]

[18]: 'i'

[23]: my_text[2]

[23]: 'r'

[25]: my_text + "hiiii"

[25]: 'Kirtihiiii'

[26]: my_text*3

[26]: 'KirtiKirtiKirti'

[28]: my_text[0:-1]

[28]: 'Kirt'

[29]: my_text[1:]

[29]: 'irti'

[30]: my_text[:4]

2
[30]: 'Kirt'

[32]: my_text[0::2]

[32]: 'Kri'

[35]: print("i" not in my_text)

False

[38]: my_text.upper()

[38]: 'KIRTI'

[39]: my_text.lower()

[39]: 'kirti'

[44]: my_text + " $"

[44]: 'Kirti $'

[45]: print(my_text.lstrip("$"))

Kirti

[48]: my_text.count("i")

[48]: 2

[52]: print("my name is {} {} {}.".format(my_text,a,b))

my name is xyza 12 3.25.

[53]: list1 = [1,2,3,34,5,"kite"]


print(list1)

[1, 2, 3, 34, 5, 'kite']

[54]: tup = 1,3,3,5,56,6

[55]: tup

[55]: (1, 3, 3, 5, 56, 6)

[57]: list1[3] = 3

[58]: list1

3
[58]: [1, 2, 3, 3, 5, 'kite']

[82]: tup[4] = 6

[65]: set1 = set(list1)

[1]: name = "xyz"


a = 12
b = 3.25

[2]: print(type(name))
print(type(a))
print(type(b))

<class 'str'>
<class 'int'>
<class 'float'>

[50]: my_text = input("enter your name:" )

enter your name: xyza

[5]: print(my_text)

Kirti

[7]: x = True
print(type(x))

<class 'bool'>

[8]: a+b

[8]: 15.25

[9]: a-b

[9]: 8.75

[10]: a*b

[10]: 39.0

[11]: a/b

[11]: 3.6923076923076925

[12]: a//b

4
[12]: 3.0

[13]: a%b

[13]: 2.25

[14]: a**b

[14]: 3216.170393056856

[16]: print(len(my_text))

[17]: my_text[1]

[17]: 'i'

[18]: my_text[-1]

[18]: 'i'

[23]: my_text[2]

[23]: 'r'

[25]: my_text + "hiiii"

[25]: 'Kirtihiiii'

[26]: my_text*3

[26]: 'KirtiKirtiKirti'

[28]: my_text[0:-1]

[28]: 'Kirt'

[29]: my_text[1:]

[29]: 'irti'

[30]: my_text[:4]

[30]: 'Kirt'

[32]: my_text[0::2]

5
[32]: 'Kri'

[35]: print("i" not in my_text)

False

[38]: my_text.upper()

[38]: 'KIRTI'

[39]: my_text.lower()

[39]: 'kirti'

[44]: my_text + " $"

[44]: 'Kirti $'

[45]: print(my_text.lstrip("$"))

Kirti

[48]: my_text.count("i")

[48]: 2

[52]: print("my name is {} {} {}.".format(my_text,a,b))

my name is xyza 12 3.25.

[53]: list1 = [1,2,3,34,5,"kite"]


print(list1)

[1, 2, 3, 34, 5, 'kite']

[54]: tup = 1,3,3,5,56,6

[55]: tup

[55]: (1, 3, 3, 5, 56, 6)

[57]: list1[3] = 3

[58]: list1

[58]: [1, 2, 3, 3, 5, 'kite']

[82]: tup[4] = 6

6
[65]: set1 = set(list1)

[66]: set1

[66]: {1, 2, 3, 5, 'kite'}

[67]: tup = list(tup)

[68]: type(tup)

[68]: list

[73]: data = {"name":"value","nope":5,2: [3,4]}

[74]: data

[74]: {'name': 'value', 'nope': 5, 2: [3, 4]}

[75]: data["name"]5,2

[75]: 'value'

[76]: [Link]()

[76]: dict_keys(['name', 'nope', 2])

[77]: [Link]()

[77]: dict_values(['value', 5, [3, 4]])

[81]: [Link](5)

[ ]:

[66]: set1

[66]: {1, 2, 3, 5, 'kite'}

[67]: tup = list(tup)

[68]: type(tup)

[68]: list

[73]: data = {"name":"value","nope":5,2: [3,4]}

[74]: data

7
[74]: {'name': 'value', 'nope': 5, 2: [3, 4]}

[75]: data["name"]5,2

[75]: 'value'

[76]: [Link]()

[76]: dict_keys(['name', 'nope', 2])

[77]: [Link]()

[77]: dict_values(['value', 5, [3, 4]])

[81]: [Link](5)

[ ]:

You might also like