Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Variables and Data Types | Python Basics
Python Programming Fundamentals (copy) 1774874722397

Variables and Data Types

メニューを表示するにはスワイプしてください

Variables are a fundamental concept in Python, allowing you to store and refer to data by name. A variable acts as a label for a value in memory. In Python, you create a variable by assigning it a value using the equals sign (=). When naming variables, follow these rules:

  • Variable names must start with a letter or underscore;
  • Names can contain letters, numbers, and underscores;
  • Variable names are case-sensitive;
  • Avoid using Python reserved keywords as variable names.

Assigning a value to a variable is straightforward: write the variable name, then =, then the value you want to store.

12345678910111213
# Assigning values to variables of different types # Integer variable age = 25 # Float variable temperature = 36.6 # String variable greeting = "Hello, Python!" # Boolean variable is_active = True

Python provides several built-in data types to represent different kinds of information. The most common are:

  • int for whole numbers, such as 25;
  • float for decimal numbers, such as 36.6;
  • str for text, such as "Hello, Python!";
  • bool for logical values, either True or False.

Each variable you assign is automatically given a data type based on the value you provide. The examples above show how to create variables with these types.

123456
# Checking the data types of variables using type() print(type(age)) # Output: <class 'int'> print(type(temperature)) # Output: <class 'float'> print(type(greeting)) # Output: <class 'str'> print(type(is_active)) # Output: <class 'bool'>
すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  1

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 1.  1
some-alt