⚡0 XP🔥0

Ch 5 · Getting Started with Python | पायथन से शुरुआत

Lesson 5 of 11 ⏱ 3 min read ✎ 1 exercises ❓ 5-question quiz ▶ Runs Python

Features of Python, execution modes, keywords and identifiers, variables, data types, operators, expressions, input and output, type conversion and comments.

Features#

High-level, interpreted, free and open source, easy syntax, case-sensitive, portable, large library. Modes: interactive (>>> prompt) and script (.py file).

Tokens#

Keywords (if, else, while, for, def, True, None…), identifiers (names - start with a letter or _, no spaces, not a keyword), literals, operators, punctuators.

Data types#

int, float, complex, bool, str, list, tuple, dict, None. Mutable: list, dict, set. Immutable: int, float, str, tuple.

▶ Try it YourselfPython
Ctrl + Enter to run
हिंदी में समझें

पायथन एक उच्च-स्तरीय, इंटरप्रेटेड और केस-सेंसिटिव भाषा है। input() हमेशा स्ट्रिंग लौटाता है, इसलिए संख्या के लिए int() या float() से टाइप बदलना पड़ता है।

Operators#

Type Operators
Arithmetic + − * / // % **
Relational == != > < >= <=
Logical and, or, not
Assignment = += −= *= /=
Identity / membership is, is not / in, not in

Precedence (high → low): **, unary −, * / // %, + −, relational, not, and, or.

▶ Try it YourselfPython
Ctrl + Enter to run

Exam tips#

  • Predict output of expressions with // and %, and type conversion; identify invalid identifiers.

Practice Exercises

Write your code, then press Check. Your program is tested automatically.

1

Simple interest

Read principal, rate and time (one per line, numbers) and print the simple interest P * R * T / 100 as a float.

Test input:
1000
5
2
Expected output:
100.0

Quick Quiz

Q1.

Which is a valid identifier?

Q2.

17 // 5 evaluates to

Q3.

input() returns a value of type

Q4.

Which data type is immutable?

Q5.

2 ** 3 evaluates to