Python Tutorial ( PDFDrive )

28.10.2021 Views

print "radians(3) : ", math.radians(3)print "radians(-3) : ", math.radians(-3)print "radians(0) : ", math.radians(0)print "radians(math.pi) : ", math.radians(math.pi)print "radians(math.pi/2) : ", math.radians(math.pi/2)print "radians(math.pi/4) : ", math.radians(math.pi/4)Let us compile and run the above program, this will produce the following result:radians(3) : 0.0523598775598radians(-3) : -0.0523598775598radians(0) : 0.0radians(math.pi) : 0.0548311355616radians(math.pi/2) : 0.0274155677808radians(math.pi/4) : 0.0137077838904Mathematical Constants: The module also defines two mathematical constants:ConstantsDescriptionPiThe mathematical constant pi.E The mathematical constant e.TUTORIALS POINT Simply Easy Learning

CHAPTER9Python StringsStrings are amongst the most popular types in Python. We can create them simply by enclosing charactersin quotes. Python treats single quotes the same as double quotes.Creating strings is as simple as assigning a value to a variable. For example:var1 = 'Hello World!'var2 = "Python Programming"Accessing Values in Strings: Python does not support a character type; these are treated as strings of length one, thus also considered asubstring.To access substrings, use the square brackets for slicing along with the index or indices to obtain your substring.Following is a simple example:#!/usr/bin/pythonvar1 = 'Hello World!'var2 = "Python Programming"print "var1[0]: ", var1[0]print "var2[1:5]: ", var2[1:5]When the above code is executed, it produces the following result:var1[0]: Hvar2[1:5]: ythoUpdating Strings: You can "update" an existing string by (re)assigning a variable to another string. The new value can be related toits previous value or to a completely different string altogether. Following is a simple example:#!/usr/bin/pythonvar1 = 'Hello World!'TUTORIALS POINT Simply Easy Learning

CHAPTER

9

Python Strings

Strings are amongst the most popular types in Python. We can create them simply by enclosing characters

in quotes. Python treats single quotes the same as double quotes.

Creating strings is as simple as assigning a value to a variable. For example:

var1 = 'Hello World!'

var2 = "Python Programming"

Accessing Values in Strings:

Python does not support a character type; these are treated as strings of length one, thus also considered a

substring.

To access substrings, use the square brackets for slicing along with the index or indices to obtain your substring.

Following is a simple example:

#!/usr/bin/python

var1 = 'Hello World!'

var2 = "Python Programming"

print "var1[0]: ", var1[0]

print "var2[1:5]: ", var2[1:5]

When the above code is executed, it produces the following result:

var1[0]: H

var2[1:5]: ytho

Updating Strings:

You can "update" an existing string by (re)assigning a variable to another string. The new value can be related to

its previous value or to a completely different string altogether. Following is a simple example:

#!/usr/bin/python

var1 = 'Hello World!'

TUTORIALS POINT

Simply Easy Learning

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!