Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- code = '''
- # Comment
- import re, tkinter
- # Function definition
- def add(a, b):
- return a + b
- # Function call
- result = add(2, 3)
- # Assignment
- x = 10
- # If statement
- if x > 5:
- print("x is greater than 5")
- else:
- print("x is less than or equal to 5")
- # For loop
- for i in range(5):
- print(i)
- # For loop with steps
- for i in range(20, 100, 10):
- print(i)
- # While loop
- count = 0
- while count < 5:
- print(count)
- count += 1
- # Class definition
- class MyClass:
- def __init__(self):
- self.value = 0
- def increment(self):
- self.value += 1
- # Class instantiation
- obj = MyClass()
- # Method call
- obj.increment()
- # Exception handling
- try:
- result = 10 / 0
- except ZeroDivisionError as e:
- print("Error:", str(e))
- # Regular expression matching
- pattern = r'\w+'
- string = "Hello, World!"
- match = re.search(pattern, string)
- if match:
- print("Match found:", match.group())
- # Canvas
- canvas = Canvas(width=100, height=200)
- # Entry
- my_entry = Entry()
- # Text
- text_widget = Text("Some text")
- # Listbox
- my_listbox = Listbox(values=[1, 2, 3])
- # Label
- label_widget = Label("Hello")
- # Button
- button_widget = Button(text="Click me", command=my_function)
- # Radiobutton
- my_radio = Radiobutton(value="option1")
- # Slider
- my_slider = Slider(min_value=0, max_value=100, step=5)
- # Bind
- bind_event("<click>", "my_element", "my_function")
- # create_polygon
- create_polygon(points=[10, 20, 30, 40, 50, 60])
- # create_arc
- create_arc(x=10, y=20, width=30, height=40, start=50, extent=60)
- # Menu
- my_menu = Menu("My Menu", items=["Item 1", "Item 2", "Item 3"])
- # OptionMenu
- my_variable = OptionMenu(menu=my_menu, options=["Option 1", "Option 2"])
- # Message
- message_widget = Message("Hello")
- # Exception handling
- try:
- # Some code
- pass
- except MyException as e:
- # Handle exception
- pass
- # Global variables
- x = None
- y = None
- z = None
- # For loop
- for i in range(1, 10, 2):
- pass
- # Range
- values = list(range(5))
- # Dictionary
- data = {"a": 1, "b": 2, "c": 3}
- # ImageFilter
- blur_filter = ImageFilter.BLUR()
- # 'self'
- self.value = 10
- # Import
- from module import function, constant
- # Function definition
- def my_function():
- pass
- # Return statement
- def square(x):
- return x * x
- # Try-except-finally
- try:
- # Some code
- pass
- except MyException as e:
- # Handle exception
- pass
- finally:
- # Cleanup code
- pass
- # Raise exception
- raise ValueError("Invalid value")
- # Class definition
- class MyClass:
- def __init__(self):
- self.value = 0
- def increment(self):
- self.value += 1
- # Print statement
- print("Hello, World!")
- # min() and max()
- x = min(5, 3, 8)
- y = max(10, 20, 30)
- # Comparison operators
- if x != y:
- print("x is not equal to y")
- # None
- value = None
- # len()
- length = len([1, 2, 3])
- # sorted()
- sorted_list = sorted([3, 1, 2])
- # rsplit()
- parts = "Hello, World!".rsplit(",")
- # str() and repr()
- s = str(10)
- r = repr(3.14)
- # int()
- integer = int("42")
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement