Вы находитесь на странице: 1из 2

Python

Basics types of data.


-String is basically a plain text -It is a data type in Python and it just stores
plain text.

-We can also store a number, while storing number we dont need quotation mark.

-Boolean Value- it is essentially a true or false value.

Working with Strings in Python.

- In order to use a string we have to use Quation mark- ""


-to insert a new line in the same string we use \n
example before -- print("Girrafe Academy")
to insert new line use \n or quation mark
after---- print("Girrafe\nAcademy") or print("Girrafe\"Academy")

To create string variable

phrase="Giraffe Academy"
print(phrase)
-Concatenation- It is basically the process of taking a string and appending
another string onto it
example = print(phrase + "is cool")
-Function - it is basically a little block of code that we can run and it will
perform a specific operation for us. We can use function to
modify our strings, get info about our strings.
print(phrase.lower())- Convert entrie string in lower case
print(phrase.upper())- Convert entire string in upper case
print(phrase.isupper())- to check if a string is entirely upper case or lower, it
will give true or false value.
print(phrase.upper().isupper())- it will first run n change the string in upper
case and den check whether the string is entirely in upper case or lower.

Length function- to know no. of characters in a string


example- print(len(phrase))
In python when we use indexes on string it starts with 0. i.e 0=G,1=i,2=r and so on
Index function- It tells us where the specific character or string is located
inside our phrase
example- print(phrase.indec("G")) i.e 0=G,1=i,2=r and so on
Replace- Function
example- print(phrase.replace("Giraffe","Elephant")) - This will replace Giraffe
with Elephant

Working with Numbers


print(2) - This will print number 2 on the screen
We can do addition subtraction multiplication or division within this
example print(2+2) - This will print 4 on the screen
modulas operator i.e. print(10%3) - This is read as 10 mod 3 - This will take the
first number divide it by the second number and spit out the remainder- it shows
the remainder
We can store them inside the variable
example-
my_num=5
print(my_num) - this will print 5 on the screen

We can convert number into a string


print(str(my_num))
print(str(my_num)+ "my favorite number")

Other functions
abs - absolute value - this gives us the asolute value of number
example- my_num=5
print(abs(my_num))

Вам также может понравиться