Ncert solutions for class 11 Computer Science Python Chapter 8 Getting Started with Python are prepared by CBSE student eCARE expert to score good marks in class 11. Classes 11 Computer Science Python Chapter 8 Getting Started with Python contain many topics which are very important to score good in class 11. There are some important topic mentioned below:
In Python, variables that are only referenced inside a function are implicitly global. If a variable is assigned a new value anywhere within the function’s body, it’s assumed to be a local. If a variable is ever assigned a new value inside the function, the variable is implicitly local, and you need to explicitly declare it as ‘global’. Though a bit surprising at first, a moment’s consideration explains this. On one hand, requiring global for assigned variables provides a bar against unintended side-effects. On the other hand, if global was required for all global references, you will be using global all the time. You have to declare as global every reference to a builtin function or to a component of an imported module. This clutter would defeat the usefulness of the global declaration for identifying side-effect.
Yes, Python support data type conversion. To convert between built-in types, programmer simply use the type name as a function. There are several built-in functions to perform conversion from one data type to another. These functions return a new object represting the converted value.
|int (x [, base])||Converts x to an integer, base specifies the base if x is a string.|
|long [x [, base])||Converts x to a long integer, base specifies the base if x is a string.|
|float (x)||Converts x to a floatingpoint number.|
complex (real, [ing])
|Creates a complex number.|
|str (x)||Converts object x to a string representation.|
|repr (x)||Converts object x to an expression string.|
|tuple (x)||Converts x to a tuple.|
|list (x)||Converts x to a list.|
|chr (x)||Convets an integer to a character.|
|unichr (x)||Converts an integer to a Unicode character.|
|diet (x)||Creates a disetionary, x must be a sequence of tuples.|
|set (x)||Converts x to a set|
What is the difference between a keyword and an identifier ?
Keyword is a special word that has a special meaning and purpose. Keywords are reserved and are few. For example : if, else, elif etc.
Identifier is the user-defined name given to a part of a program like variable, object, functions etc. Identifiers are not reserverd. These are defined by the user but they can have letters, digits and a symbols underscore. They must begin with either a letter or underscore. For example : chess, _ch, etc.
What are literals in Python ? How many types of literals are allowed in Python ?
Literals mean constants i.e. the data items that never change value during a program run. Python allow five types of literals :
How many ways are there in Python to represent an integer literal ?
Python allows three types of integer literals :
How many types of strings are supported in Python ?
Python allows two string types :
What is “None” literal in Python ?
Python has one special literal called ‘None’. The ‘None’ literal is used to indicate something that has not yet been created. It is also used to indicate the end of lists in Python.
What factors guide the choice of identifiers in Programs ?
What will be the size of the following constants : “\a”. “\a”, “Manoj\’s”, ‘\”, “XY\ YZ”
‘\a’ – size is 1 as there is one character and it is a string literal enclosed in single quotes.
“\a” – size is 1 as there is one character enclosed in double quotes.
“Manoj\’s” – size is 7 because it is a string having 7 characters enclosed in double quotes.
“\” – size is 1. It is a character constant and is containing just one character \”.
“XY\ – size is 4. It is a multiline string create YZ” with \ in the basic string.
What is the difference between a tuple and a list ?
A tuple is immutable i.e. cannot be changed. It can be operated on only. But a list is mutable. Changes can
be done internally to it.
tuple initialization: a = (2,4,5) list initialization: a = [2,4,5]
Write various python modules convert the list to generate the output “one, two, three” ? a = [‘one’, ‘two’, ‘three’]
> > > a = [‘one’,’two’,’three’]
What would the following code yield ? word = ‘abcdefghij’
print word[:3] + word[3:]
Is there a tool to help find bugs or perform static analysis?
Yes. PyChecker is a static analysis tool that finds bugs in Python source code and warns about code complexity and style. Pylint is another tool that checks if a module satisfies a coding standard, and also makes it possible to write plug-ins to add a custom feature.
What is a tuple ?
A tuple is another sequence data type that is similar to the list. A tuple consists of a number of values separated by commas. Unlike lists, however, tuples are enclosed within parentheses.
What is a list?
Lists are the most versatile of Python’s compound data types. A list contains items separated by commas and enclosed within square brackets ([ ]). To some extent, lists are similar to arrays in C. One difference between them is that all the items belonging to a list can be of different data type.
Explain String data type.
Strings in Python are identified as a contiguous set of characters in between quotation marks. Python allows for either pairs of single or double quotes. Subsets of strings can be taken using the slice operator ( [ ] and [ : ] ) with indexes starting at 0 in the beginning of the string and working their way from -1 at the end.
What is a Number data types ?
Number data types store numeric values. They are immutable data types, which means that changing the value of a number data type results in a newly allocated object.
Write the names of all Standard Data Types.
Write a list comprehension that builds a list of the even numbers from 1 to 10 (inclusive).
foo = [x for x in range(l, 11) if (x % 2) = = 0] print foo [2,4,6,8,10]
When do you use list vs. tuple vs. dictionary vs. set?
‘List’ is like an array, individual element of list data can be accessed using indexing and can be manipulated. “Tuples” are similar to list, but there data can be changed once created through the execution of program. ‘Set’ stores unordered values and have no index. And unlike Tuples and lists, sets can have no duplicate data. “Dictionary” is similar to what their name is. It consist of pairs of keys and thier corresponding values.
Explain the dictionary in Python.
What is PEP 8?
PEP 8 is a coding convention(a set of recommendations) to write your Python code in order to make it more readable and useful for those after you.
Explain how Python is interpreted.
Python program runs directly from the source code. Each type Python programs executed code is required. Python converts source code written by the programmer into intermediate language which is again translated into the native language/ machine language that is executed. So Python is an interpreted language.