Back to Browse

Python Shell Session - Variables, Numbers, Expressions, Strings and Lists

28 views
Jul 10, 2024
2:17

Doing a Python Shell Session - Variables, Numbers, Expressions, Strings and Lists. Use of print statement. Defining variable x and giving the value of 4. Giving the expression of x**2 and printing it. The ** is exponentiation. For example, 4**2 gives 16. Conversion of variable x to a string and then getting the length of the string. Define the variable xstr, which is equal to str(x). The str function converts a number to a string. Using xstr[0] to get the first character, which gives 4. Adding 1 to x, which gives 5. Define a variable y to be a list of 1 element. Getting the first element of a list, written as y[0]. Defining a list myarr to be 1,2,3,4,5 and 6. Getting the first element of myarr, which is 1. Getting the length of the list myarr, which is 6.

Download

0 formats

No download links available.

Python Shell Session - Variables, Numbers, Expressions, Strings and Lists | NatokHD