Loading...
More Python Posts
import mysql.connectormydb = mysql.connector.connect(host="localhost",user="yourusername",password="yourpassword")mycursor = mydb.cursor()mycursor.execute("CREATE DATABASE mydatabase")
filename = "data.txt"data = "Hello, World!"with open(filename, "a") as file:file.write(data)
from math import pidef rads_to_degrees(rad):return (rad * 180.0) / pirads_to_degrees(pi / 2) # 90.0
from time import sleepdef delay(fn, ms, *args):sleep(ms / 1000)return fn(*args)delay(lambda x: print(x), 1000, 'later') # prints 'later' after one second
import sys# sample TuplesTuple1 = ("A", 1, "B", 2, "C", 3)Tuple2 = ("Geek1", "Raju", "Geek2", "Nikhil", "Geek3", "Deepanshu")Tuple3 = ((1, "Lion"), ( 2, "Tiger"), (3, "Fox"), (4, "Wolf"))# print the sizes of sample Tuplesprint("Size of Tuple1: " + str(sys.getsizeof(Tuple1)) + "bytes")print("Size of Tuple2: " + str(sys.getsizeof(Tuple2)) + "bytes")print("Size of Tuple3: " + str(sys.getsizeof(Tuple3)) + "bytes")
from functools import partialdef curry(fn, *args):return partial(fn, *args)add = lambda x, y: x + yadd10 = curry(add, 10)add10(20) # 30