Lesson 2 String in Python
Lesson 2 String in Python
Lesson 2 String in Python
Numbers
and
Variables
Prepared by:
Jennifer O. Contreras
Python Casting
Python Casting
– Casting in python is therefore done using
constructor functions:
– int() - constructs an integer number from an
integer literal, a float literal (by rounding down to
the previous whole number), or a string literal
(providing the string represents a whole number)
– float() - constructs a float number from an integer
literal, a float literal or a string literal (providing the
string represents a float or an integer)
– str() - constructs a string from a wide variety of
data types, including strings, integer literals and
float literals
Python Booleans
Boolean Values
– Booleans represent one of two values: TRUE or FALSE
– When you compare two values, the expression is
evaluated and Python returns the Boolean answer:
String
– string is a sequence of characters
– Strings are what we call text, or keyboard characters,
in a programming language; they are groups (or
“strings”) of letters, numbers, and symbols.
– Strings are basically just a bunch of words.
– The words can be in English or any other language that
is supported in the Unicode standard
String literals
– String literals in python are surrounded by either single quotation
marks, or double quotation marks.
– 'hello' is the same as "hello".
– You can display a string literal with the print() function:
Assign String to a Variable