Python MCQs with explanation

Which of the following statements is correct for variable names in Python language?

  1. All variable names must begin with an underscore.
  2. Unlimited length
  3. The variable name length is a maximum of 2.
  4. All of the above



Answer: 
Option b: Unlimited length

The correct statement for variable names in the Python language is: "Variable names have unlimited length."

In Python, variable names can be of any length and can contain letters (both uppercase and lowercase), numbers, and underscores. 

We must follow the below rules to while writing variables in Python
  1. A variable name must start with a letter or underscore character.
  2. A variable name cannot start with a number.
  3. A variable name can contain only alpha-numeric characters and underscores. eg: pp_score_99
  4. Variable names are case sensitive (age, Age, AGE are not same and are 3 different variables.
  5. A varible name cannot be of a python keyword.
We use many cases to variables more readable-
  1. camelCase - Each word except first, start with a capital letter. Eg: myVariableName
  2. PascalCase - Every word in a variable name starts with capital letter. Eg: MyVariableName
  3. snake_case - between every word we keep underscore. All letters are case sensitive. Eg: my_variable_name (correct), My_Variable_Name(incorrect)
  4. kebab-case: In this convention, words are separated by hyphens ("-"). It is commonly used in HTML, CSS, and some JavaScript frameworks. Eg: my-variable-name
  5. UPPER_CASE: This convention uses all capital letters with underscores between words. It is typically used for constants or variables that should not be modified. Eg: MY_CONSTANT, VAR

NAMESTE GUYS, Feel free to ask your doubts and all computer science related questions in comment sections or through contact form. Thank you.

Post a Comment

0 Comments