0% found this document useful (0 votes)
2 views2 pages

Python 50 Basic Codes

The document contains 50 basic Python code examples demonstrating fundamental programming concepts. It includes examples of printing, variable assignment, control flow, loops, functions, data structures, and file handling. Each example is concise and illustrates a specific aspect of Python programming.

Uploaded by

akmal.game.2000
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)
2 views2 pages

Python 50 Basic Codes

The document contains 50 basic Python code examples demonstrating fundamental programming concepts. It includes examples of printing, variable assignment, control flow, loops, functions, data structures, and file handling. Each example is concise and illustrates a specific aspect of Python programming.

Uploaded by

akmal.game.2000
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

50 Basic Python Code Examples

1. print('Hello World')

2. name = 'Akmal'
print(name)

3. x = 5
y = 3
print(x + y)

4. print(10 - 2)

5. print(4 * 5)

6. print(10 / 2)

7. print(10 % 3)

8. print(2 ** 3)

9. name = input('Enter your name: ')


print(name)

10. age = int(input('Enter age: '))


print(age)

11. if 5 > 2:
print('Yes')

12. if 3 > 5:
print('No')
else:
print('Yes')

13. for i in range(5):


print(i)

14. while True:


break

15. for i in range(1,6):


print(i)

16. print(len('hello'))

17. print('hello'.upper())

18. print('HELLO'.lower())

19. print('hello'.capitalize())

20. print('hello world'.split())

21. a = [1,2,3]
print(a)

22. [Link](4)
print(a)

23. [Link](2)
print(a)

24. print(a[0])

25. print(a[-1])
26. d = {'name':'Akmal'}
print(d)

27. print(d['name'])

28. d['age'] = 15
print(d)

29. for k,v in [Link]():


print(k,v)

30. def hello():


print('Hello')
hello()

31. def add(a,b):


return a+b
print(add(2,3))

32. import math


print([Link](16))

33. import random


print([Link](1,10))

34. try:
print(1/0)
except:
print('Error')

35. with open('[Link]','w') as f:


[Link]('Hello')

36. with open('[Link]','r') as f:


print([Link]())

37. print(type(5))

38. print(type('hi'))

39. print(bool(1))

40. print(bool(0))

41. for i in range(3):


for j in range(3):
print(i,j)

42. print(sum([1,2,3]))

43. print(max([1,2,3]))

44. print(min([1,2,3]))

45. print(sorted([3,1,2]))

46. a = set([1,2,2,3])
print(a)

47. print('a' in 'apple')

48. print('x' not in 'apple')

49. print(list(range(5)))

50. print('Done!')

You might also like