How to declare a variable in PythonPython is a dynamic-typed language, which means we don’t need to mention the variable type or declare before using it. It makes to Python the most efficient and easy to use language. Every variable is treated as an object in Python. Before declaring a variable, we must follow the given rules.
Let’s understand the declaration of a few basic variables. NumbersPython supports three types of numbers – integer, floating point numbers, and complex. We can declare a variable with any length, there is no restriction declares any length of the variable. Use the following syntax to declare the number type variables. Example – Output: The type of a <class 'int'> 25 The type of b <class 'float'> 12.5 The type of c <class 'complex'> c is a complex number True StringsThe string is the sequence of Unicode characters. It is declared using single quotes, double quotes, or triple quotes. Let’s understand the following example. Example – Output: JavaTpoint <class 'str'> JavaTpoint <class 'str'> This is string using the triple Quotes <class 'str'> Multiple Assignments1. Assigning multiple values to multiple variables We can assign the more than one variable simultaneously on the same line. For example – Output: 5 4 Values are printed in the given order. 2. Assign a single value to the multiple variables We can assign the single value to the multiple variables on the same line. Consider the following example. Example – Output: JavaTpoint JavaTpoint JavaTpoint |
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/263623.html