Header Ads Widget

Ticker

6/random

Python Variable

 
Python Variable


In Python, a variable is a name given to a memory location to store data. Variables can hold different types of data, and their type is dynamically determined. Here are some common variable types in Python:


1. Integer (int):


 Represents whole numbers without any decimal points.

   

```python

   age = 25

   ```

2. Float (float):


 Represents real numbers with decimal points.

   

```python

   height = 5.8

   ```

3. String (str):


Represents a sequence of characters enclosed in single or double quotes.

```python

   name = "John"

   ```

4. Boolean (bool):


 Represents either True or False.


   ```python

   is_adult = True

   ```


5. List:

Ordered collection of items.

   

```python

   numbers = [1, 2, 3, 4, 5]

   ```


6. Tuple:


Similar to a list but immutable (cannot be changed after creation).

   

```python

   coordinates = (3, 5)

   ```


7. Dictionary


Unordered collection of key-value pairs.


 ```python

   person = {'name': 'Alice', 'age': 30}

   ```

8. Set: 


Unordered collection of unique items.


   ```python

   unique_numbers = {1, 2, 3, 4, 5}

   ```

These are some fundamental variable types in Python. Each type has its own set of operations and use cases.


Post a Comment

0 Comments