Skip to content

Latest commit

 

History

History
72 lines (31 loc) · 2.02 KB

notes.md

File metadata and controls

72 lines (31 loc) · 2.02 KB
  • print() => show the output

  • print(f"") => to include varible in string using {}

  • input() => aske the user for data

  • str() => converted into a string

  • int() => converted into a integer point number

  • float() => converted into a floating point number

if condition:
    expression
else:
    expression
  • The words condition and Boolean expression can often be used interchangeably.

  • The function len can be used to find out the length of a string, among other things. The function returns the number of characters in a string.

  • Python comparison operators can also be used on strings. String a is smaller than string b if it comes alphabetically before b. Notice however that the comparison is only reliable if:

    • the characters compared are of the same case, i.e. both UPPERCASE or both lowercase
    • only the standard English alphabet of a to z, or A to Z, is used.

Combining conditions

  • The condition x >= a and x <= b, x >= a or x <= b, not a, x >= a <= b

Simple loops

  • to use sqrt fun do this: from math import sqrt

Working with strings

  • substrings and slices:

    • A substring of a string is a sequence of characters that forms a part of the string.

    • In Python programming, the process of selecting substrings is usually called slicing, and a substring is often referred to as a slice of the string. The two terms can often be used interchangeably.

    • you can do so with the notation [a:b]. This means the slice begins at the index a and ends at the last character before index b - that is, including the first, but excluding the last.

  • Searching for substrings:

    • The in operator can tell us if a string contains a particular substring. The Boolean expression a in b is true, if b contains the substring a.
  • Python string method find. It takes the substring searched for as an argument, and returns either the first index where it is found, or -1 if the substring is not found within the string.

Defining functions