Python
  • Getting Started
    • Input and Output
    • Variables
    • Data Types
    • Conditional Structures
      • Humidity Level
      • Financial Transactions
      • Fruit-Vending Machine
      • Magic While
      • FizzBuzz
    • Functions
      • Hashtag Generator
  • Data Structures
    • Lists
    • Dictionary
    • Set
    • Interpreter Expressions
  • OOPs
    • Classes and Objects
    • Exception Handling
      • Simple Calculator
  • System Programming
    • File Operations
    • Directory Navigation
    • Process Creation
    • Threads
Powered by GitBook
On this page
  • Create an Expression
  • List Expression
  • Dictionary Expression
  • Generator Expression
  • Conditional Expressions
  1. Data Structures

Interpreter Expressions

I LOVE DOING THIS :)

Expressions are representations of values, they are totally different from statements and functions since they perform any action, Meanwhile expressions are just the representation

Create an Expression

They only contain Identifiers, Literals, and Operators

  • Any name that is used to define a class, function, variable module, or object is an Identifier

  • There are the string literals, byte literals, integer literals, floating point literals, and imaginary literals, basically which means the independent usage of data types

  • Operators are nothing but + - * / % > < >= <= == >> <<

List Expression

One liner syntax - for loop

>>> [x for x in range(10)]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Dictionary Expression

One liner syntax - for loop

{x:x*2 for x in range(5)}
{0: 0, 1: 2, 2: 4, 3: 6, 4: 8}

Generator Expression

One liner syntax - for loop

Will initialize a generator object that returns the values within 5 when the object is called

>>> d0p = (x for x in range(5))
<generator object <genexpr> at 0x7fec47aee870>
>>> list(d0p)
[0, 1, 2, 3, 4]

Conditional Expressions

true_value if Condition else false_value

>>> x = "1" if True else "2"
>>> x
'1'
PreviousSetNextClasses and Objects

Last updated 2 years ago