Untitled

mail@pastecode.io avatar
unknown
python
22 days ago
311 B
1
Indexable
Never
x = 10  # Global variable

def add_to_x(y):
    global x  # Declare x as global
    x += y  # Modify the global variable

add_to_x(5)
print(x)  # Outputs: 15


def write_to_file(filename, data):
    with open(filename, 'w') as f:
        f.write(data)

write_to_file('test.txt', 'Hello, World!')
Leave a Comment