You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 01.Variables/README.md
+82-3Lines changed: 82 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,9 +13,7 @@ Welcome to the Python Variables section! In this section, you'll learn about the
13
13
-[String Variables](#-string-variables)
14
14
-[Float Variables](#-float-variables)
15
15
-[Integer Variables](#-integer-variables)
16
-
-[Boolean Variables](#boolean-variables)
17
-
-[Summary](#summary)
18
-
16
+
-[Boolean Variables](#-boolean-variables)
19
17
## 📚 Introduction
20
18
21
19
Variables are containers for storing data values. In Python, you don't need to declare the type of a variable, as Python is dynamically typed. This means you can assign different types of values to the same variable.
@@ -223,4 +221,85 @@ print(min_value) # Output: 1
223
221
string_number ="123"
224
222
integer_number =int(string_number)
225
223
print(integer_number) # Output: 123
224
+
```
225
+
# ✅ Boolean Variables
226
+
227
+
A boolean variable is used to store one of two values: `True` or `False`. Booleans are often used in conditional statements and loops to control the flow of a program.
228
+
229
+
### Creating Boolean Variables
230
+
231
+
- You can create a boolean variable by assigning `True` or `False` to a variable name.
232
+
233
+
```python
234
+
# Example of creating boolean variables
235
+
is_student =True
236
+
has_passed =False
237
+
print(is_student) # Output: True
238
+
print(has_passed) # Output: False
239
+
```
240
+
241
+
### Logical Operations with Booleans
242
+
243
+
- You can perform various logical operations with booleans, such as `and`, `or`,`not`.
244
+
245
+
```python
246
+
# Logical operations with booleans
247
+
a =True
248
+
b =False
249
+
250
+
and_operation = a and b
251
+
or_operation = a or b
252
+
not_operation =not a
253
+
254
+
print(and_operation) # Output: False
255
+
print(or_operation) # Output: True
256
+
print(not_operation) # Output: False
257
+
```
258
+
259
+
### Comparison Operators
260
+
261
+
Comparison operators are used to compare values. They return a boolean value (True or False). Common comparison operators include:
262
+
263
+
-`==`: Equal to
264
+
-`!=`: Not equal to
265
+
-`>`: Greater than
266
+
-`<`: Less than
267
+
-`>=`: Greater than or equal to
268
+
-`<=`: Less than or equal to
269
+
270
+
```python
271
+
# Comparison operations
272
+
x =10
273
+
y =20
274
+
275
+
equal = x == y
276
+
not_equal = x != y
277
+
greater_than = x > y
278
+
less_than = x < y
279
+
greater_than_or_equal = x >= y
280
+
less_than_or_equal = x <= y
281
+
282
+
print(equal) # Output: False
283
+
print(not_equal) # Output: True
284
+
print(greater_than) # Output: False
285
+
print(less_than) # Output: True
286
+
print(greater_than_or_equal) # Output: False
287
+
print(less_than_or_equal) # Output: True
288
+
```
289
+
290
+
### Boolean Methods
291
+
292
+
Python provides several built-in functions that return boolean values. Here are some common ones:
293
+
294
+
-`bool()`: Converts a value to a boolean.
295
+
-`isinstance()`: Checks if an object is an instance of a specific class or type.
0 commit comments