Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.
importrequests url ='https://www.w3schools.com/python/demopage.php' myobj = {'somekey':'somevalue'} x = requests.post(url, json = myobj) print(x.text) Run Example » Definition and Usage Thepost()method sends a POST request to the specified url. ...
x = requests.head('https://www.w3schools.com/python/demopage.php') print(x.headers) Run Example » Definition and Usage Thehead()method sends a HEAD request to the specified url. HEAD requests are done when you do not need the content of the file, but only the status_code or HTTP...
❮ String Methods ExampleGet your own Python Server UTF-8 encode the string: txt ="My name is Ståle" x = txt.encode() print(x) Run example » Definition and Usage Theencode()method encodes the string, using the specified encoding. If no encoding is specified, UTF-8 will be used...
❮ Set Methods ExampleGet your own Python Server Return a set that contains all items from both sets, duplicates are excluded: x = {"apple","banana","cherry"} y = {"google","microsoft","apple"} z = x.union(y) print(z)
ExampleGet your own Python Server Create a mapping table, and use it in thetranslate()method to replace any "S" characters with a "P" character: txt ="Hello Sam!" mytable =str.maketrans("S","P") print(txt.translate(mytable)) ...
ExampleGet your own Python Server Sort the list alphabetically: cars = ['Ford','BMW','Volvo'] cars.sort() Try it Yourself » Definition and Usage Thesort()method sorts the list ascending by default. You can also make a function to decide the sorting criteria(s). ...
ExampleGet your own Python Server Join all items in a tuple into a string, using a hash character as separator: myTuple = ("John","Peter","Vicky") x ="#".join(myTuple) print(x) Try it Yourself » Definition and Usage Thejoin()method takes all items in an iterable and joins the...
❮ File Methods ExampleGet your own Python Server Return all lines in the file, as a list where each line is an item in the list object: f =open("demofile.txt","r") print(f.readlines()) Run Example » Definition and Usage ...