官术网_书友最值得收藏!

  • Learn Python in 7 Days
  • Mohit Bhaskar N. Das
  • 243字
  • 2021-07-09 20:40:22

Variables

So, what is a variable? Consider that your house needs a name. You place a nameplate at the front gate of your house. People will now recognize your house through that nameplate. That nameplate can be considered as variable. Like a nameplate points to the house, a variable points to the value that is stored in memory. When you create a variable, the interpreter will reserve some space in the memory to store values. Depending on the data type of the variable, the interpreter allocates memory and makes a decision to store a particular data type in the reserved memory. Various data types, such as integers, decimals, or characters, can be stored by assigning different data types to the variables. Python variables are usually dynamically typed, that is, the type of the variable is interpreted during runtime and you need not specifically provide a type to the variable name, unlike what other programming languages require. There are certain rules or naming conventions for naming variables. The following are the rules:

  • Reserved key words such as if, else, and so on cannot be used for naming variables
  • Variable names can begin with _, $, or a letter
  • Variable names can be in lower case and uppercase
  • Variable names cannot start with a number
  • White space characters are not allowed in the naming of a variable

You can assign values to the variable using = or assignment operator.

Syntax:

<variable name>= < expression > 
主站蜘蛛池模板: 达日县| 铁力市| 自治县| 贡嘎县| 湘乡市| 陈巴尔虎旗| 体育| 新沂市| 郴州市| 镇安县| 文安县| 郓城县| 石台县| 新蔡县| 银川市| 乌拉特前旗| 安溪县| 西林县| 九龙坡区| 新源县| 松桃| 晋中市| 章丘市| 宁乡县| 大足县| 登封市| 锡林浩特市| 正阳县| 江阴市| 黄大仙区| 雅江县| 闽清县| 澜沧| 诸城市| 西宁市| 马山县| 平阳县| 同心县| 夏津县| 深水埗区| 上杭县|