Advertisement
here2share

# basic_test.py

Sep 12th, 2016
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.42 KB | None | 0 0
  1. # basic_test.py
  2. import string
  3.  
  4. # this is a comment
  5. print "hello python world"
  6. print """this
  7. spans more than one line"""
  8. print "hello python world\n"
  9. print "hello python world "*3
  10. print "hello python",
  11. print "world"
  12. print "hello python world\
  13. over more than one line"
  14. print("this is it again")
  15. print r"\this is a raw string\\"
  16. print "\thello python world"
  17. print "hello"+'''python'''+'world'
  18. print "hello python world".capitalize()
  19. print "hello python world".isspace()
  20. print "hello python world".istitle()
  21. print "hello python world".isupper()
  22. print "hello python world".islower()
  23. print "hello python world".isalnum()
  24. print "hello python world".isdigit()
  25. print "hello python world".isalpha()
  26. print "hello python world".upper()
  27. print "hello python world".lower()
  28. print "hello python world".title()
  29. print "hello python world".count("l")
  30. print len("hello python world")
  31. print "hello python world".startswith("h")
  32. print "hello python world".endswith("d")
  33. print "hello python world".find("y",1)
  34. print "hello python world".replace("l","X")
  35. print "hello python world".center(36)
  36. print "hello python world".center(36,"-")
  37. print "hello python world".swapcase()
  38. print "hello python world".partition("l")
  39. print "hello python world".rsplit()
  40. print "hello python world".ljust(30,'!')
  41. print "hello python world".rjust(30,'*')
  42. print "hello python world".split()
  43. print "hello python world".split('l')
  44. print """
  45. hello python world
  46. hello python world
  47. hello python world""".splitlines()
  48. print "     hello      python      world     ".strip() + '!!!'
  49. z=["hello","python","world"]
  50. print "-".join(z)
  51. print "*".join("hello python world")
  52. print "ytho" in "hello python world"
  53. print "hello python world"[4:]
  54. print "hello python world"[:8]
  55. print "hello python world"[:-3]
  56. print "hello python world"[::-1]
  57. print "hello python world"[::2]
  58. s = "the quick brown fox jumps over the lazy dog"
  59. print string.capwords(s)
  60. f = string.maketrans("aeiou","12345")
  61. print string.translate(s,f)
  62. a = 1; b = "house"; c = 5; d = "e"
  63. print "%d %s +0.5%f %c" % (a,b,c,d)
  64. print("$%.2f" % (19.946))
  65. r = 5
  66. print "%f +1.2%f 2%f" % (r,r,r)
  67.  
  68. w = 10
  69. if w == 10:
  70.     print "true"
  71.  
  72. if w != 10:
  73.     print "true"
  74. else:
  75.     print "this is not true"
  76.  
  77. if w is 10:
  78.     print "hello python world "
  79. elif w != 10:
  80.         print "false"
  81. else:
  82.     print "true"
  83.  
  84. end = 10
  85. while end != 0:
  86.     end -=1
  87.     if end % 2 ==0:
  88.         print end,"even"
  89.     else:
  90.         print end,"odd"
  91.  
  92. print "7".zfill(3)
  93.  
  94. print all([True, True, True, False, True, True])
  95. print any([True, True, True, False, True, True])
  96. numbers = [1,2,3,4,5,6,7,8,9]
  97. if any(z > 3 for z in numbers):
  98.     print "there are numbers greater than 3"
  99.  
  100. print all(z > 3 for z in numbers)
  101.  
  102. print any(z in [3,6,9] for z in [1,2,3,4,5])
  103. print any(z in [6,9,12] for z in [1,2,3,4,5])
  104.  
  105. x = 3; z = 5
  106.  
  107. if (x>2) and (x!=5):
  108.     print "this is true"
  109.  
  110. if (z == 3) or (z != 5):
  111.     print "this is true"  
  112.  
  113. start = 10
  114. while start != 0:
  115.     start -= 1
  116.     print start
  117.  
  118. print "\n"
  119. begin = 10
  120. while begin:
  121.     if begin == 2:
  122.         break
  123.     begin -=1
  124.     print begin
  125.  
  126. print"\n"  
  127. begin = 10
  128. while begin:
  129.     begin -= 1
  130.     if begin == 6:
  131.         continue
  132.     print begin  
  133.  
  134. myList = [1,2,3]
  135. for i in myList:
  136.     print i
  137.  
  138. print range(10)
  139.  
  140. names = ['John', 'Mark', 'Henry', 'Marie', 'Mark', 'Marie', 'Jen']
  141. for i in names:
  142.     if names.count(i) > 1:
  143.         print i
  144.  
  145. print list(set(names))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement