Skip to main content

Variables

In Python, variables are defined with certain rules. 




Let's get started reading about them!! 

  • Don't create variable with a number
    • Eg: '12a'; #is wrong.
  • Don't define any variables with space, instead we can define with intend mark.
    • Eg: new word = Hello ; #is wrong
    • new_word = Hello ; #is correct
  • Don't create any variable contain any of these symbols:

    :'",<>/?|\!@#%^&*~-+
  • it's considered best practice (PEP8) that names are lowercase with underscores

  • avoid using Python built-in keywords
    • built-in keywords like list and str
  • avoid using the single characters l (lowercase letter el), O (uppercase letter oh) and I (uppercase letter eye) as they can be confused with 1 and 0

Comments

Popular posts from this blog

Strings

Strings are used in Python to record text information, such as names.  Strings in Python are actually a sequence, which basically means Python keeps track of every element in the string as a sequence.  For example, Python understands the string "hello' to be a sequence of letters in a specific order. This means we will be able to use indexing to grab particular letters (like the first letter, or the last letter). This idea of a sequence is an important one in Python and we will touch upon it later on in the future. In this blog we'll learn about the following: Creating Strings Printing Strings String Methods String Indexing String Slicing String Properties Creating String: 1] Strings can be created as below using single quotes or double quotes strVar = 'Python' strVar1 = "python" 2] A multi-line string can declared with triple quotes as below: strVar2 = """python language is easy to learn""" 3] A