Showing posts with label css and html interview questions. Show all posts
Showing posts with label css and html interview questions. Show all posts

Multiple-Choice Questions (MCQs) on Python coding suitable for freshers

 Multiple-Choice Questions (MCQs) on Python coding suitable for freshers:

Multiple-Choice Questions (MCQs) on Python coding suitable for freshers


1. What does the following code output?

   ```
   print(3 * 'abc')
   ```

   a) `abcabcabc`

   b) `abc3`

   c) `9`

   d) Error


2. Which of the following statements is true about Python indentation?

   a) It is optional

   b) It is for readability only

   c) It is mandatory for indicating block of code

   d) It is used for commenting


3. What is the output of the following code?

   ```

   a = [1, 2, 3]

   b = a

   b.append(4)

   print(a)

   ```

   a) `[1, 2, 3]`

   b) `[1, 2, 3, 4]`

   c) `[1, 2, 3, 4, 4]`

   d) Error


4. Which of the following is NOT a valid Python variable name?

   a) `my_var`

   b) `2var`

   c) `_var`

   d) `var_2`


5. What will be the output of the following code?

   ```

   def add(a, b=2):

       return a + b

   print(add(3))

   ```

   a) `5`

   b) `6`

   c) `3`

   d) Error


6. What does the `range(5)` function in Python represent?

   a) A list of numbers from 0 to 4

   b) A list of numbers from 1 to 5

   c) A generator that yields numbers from 0 to 4

   d) A generator that yields numbers from 1 to 5


7. What is the correct way to open a file named "example.txt" for writing in Python?

   a) `file = open("example.txt", "w")`

   b) `file = open("example.txt", "r")`

   c) `file = open("example.txt", "a")`

   d) `file = open("example.txt", "rw")`


8. What will be the output of the following code?

   ```

   my_string = "Hello, World!"

   print(my_string[7:])

   ```

   a) `World!`

   b) `W`

   c) `o, World!`

   d) `o`


9. Which of the following is used to comment multiple lines in Python?

   a) `//`

   b) `#`

   c) `/* */`

   d) `''' '''`


10. What is the output of the following code?

    ```

    print(9 // 2)

    ```

    a) `4.5`

    b) `4`

    c) `5`

    d) `4.0`


Answers:

1. a) `abcabcabc`

2. c) It is mandatory for indicating block of code

3. b) `[1, 2, 3, 4]`

4. b) `2var`

5. a) `5`

6. c) A generator that yields numbers from 0 to 4

7. a) `file = open("example.txt", "w")`

8. a) `World!`

9. d) `''' '''`

10. b) `4`


10 interview questions on Python along with their answers:


1. What is Python?

   Python is a high-level, interpreted programming language known for its simplicity and readability. It supports multiple programming paradigms like procedural, object-oriented, and functional programming.


2. What are the key features of Python?

   Python boasts several key features including:

   - Easy-to-read syntax

   - Dynamic typing

   - Automatic memory management

   - Extensive standard library

   - Cross-platform compatibility


3. What is PEP 8?

   PEP 8 is the Python Enhancement Proposal that provides guidelines and best practices for writing Python code. It covers topics such as code layout, naming conventions, and programming style.


4. What is the difference between lists and tuples in Python?

   Lists and tuples are both sequences in Python, but the main difference is that lists are mutable (can be changed) while tuples are immutable (cannot be changed). Lists are defined with square brackets `[]`, whereas tuples are defined with parentheses `()`.


5. What is the difference between `==` and `is` in Python?

   In Python, `==` is used to check if the values of two objects are equal, while `is` is used to check if the objects themselves are the same (i.e., they have the same memory address).


6. What is a decorator in Python?

   A decorator is a design pattern in Python that allows behavior to be added to functions or methods dynamically. Decorators are functions that take another function as an argument and extend its behavior without modifying its code directly.


7. Explain the concept of list comprehension.

   List comprehension is a concise way to create lists in Python. It allows you to generate a new list by applying an expression to each item in an existing iterable (such as a list, tuple, or range) and filtering the items based on a condition.


8. What is the purpose of the `__init__` method in Python classes?

   The `__init__` method is a special method in Python classes that is automatically called when a new instance of the class is created. It is used to initialize the object's attributes and perform any necessary setup.


9. What are modules in Python?

   Modules in Python are files containing Python code that define functions, classes, and variables. They allow you to organize your code into reusable units and are imported using the `import` statement.


10. What is the difference between `__str__` and `__repr__` in Python?

    Both `__str__` and `__repr__` are special methods used to represent objects as strings, but they serve different purposes. `__str__` is called by the `str()` function and is meant to provide a readable representation of an object for end-users, while `__repr__` is called by the `repr()` function and is meant to provide an unambiguous representation of an object for developers.

HTML Interview Questions & Answers For Freshers

List of 20 HTML interview questions along with their answers, suitable for freshers:

HTML Interview Auestions & Answers  For Freshers

1. What is HTML?

   - HTML stands for HyperText Markup Language. It is the standard markup language for creating web pages.


2. What are the basic components of an HTML document?

   - An HTML document consists of elements such as tags, attributes, text content, and links.


3. What is the purpose of HTML tags?

   - HTML tags are used to define the structure and content of web documents. They mark up elements such as headings, paragraphs, lists, links, images, etc.


4. Differentiate between HTML elements and tags.

   - HTML elements are the building blocks of HTML documents, while tags are used to define and enclose these elements within the document.


5. What is the basic structure of an HTML document?

   - The basic structure of an HTML document consists of the `<html>`, `<head>`, and `<body>` elements. `<html>` defines the root of the document, `<head>` contains metadata and links to external resources, and `<body>` contains the content of the document.


6. Explain the difference between HTML and XHTML.

   - HTML is more lenient and allows for errors, while XHTML is stricter and requires well-formed syntax. XHTML documents must be properly nested and close all tags.


7. What are empty elements in HTML?

   - Empty elements, also known as self-closing elements, do not have a closing tag. Examples include `<br>`, `<img>`, and `<input>`.


8. What is the purpose of the `<!DOCTYPE>` declaration?

   - The `<!DOCTYPE>` declaration specifies the document type and version of HTML being used. It helps web browsers to render the page correctly.


9. Explain the difference between `<div>` and `<span>` elements.

   - `<div>` is a block-level element used for grouping and styling larger sections of content, while `<span>` is an inline element typically used for styling smaller sections of text or elements.


10. What is the purpose of the `<meta>` tag?

    - The `<meta>` tag is used to provide metadata about the HTML document. It includes information such as character encoding, viewport settings, and authorship details.


11. What is the role of the `alt` attribute in the `<img>` tag?

    - The `alt` attribute provides alternative text for an image. It is displayed in place of the image if the image fails to load or if the user is using a screen reader.


12. What is semantic HTML?

    - Semantic HTML refers to using HTML elements that convey meaning beyond just presentation. Examples include `<header>`, `<nav>`, `<footer>`, and `<article>`.


13. Explain the difference between absolute and relative URLs.

    - Absolute URLs contain the full address of a resource, including the protocol and domain, while relative URLs specify the path relative to the current document.


14. What is the purpose of the `<iframe>` tag?

    - The `<iframe>` tag is used to embed another HTML document within the current document. It is commonly used for embedding videos, maps, or other external content.


15. What is the difference between the `id` attribute and the `class` attribute?

    - The `id` attribute uniquely identifies an element within a document, while the `class` attribute is used to group elements together for styling purposes.


16. Explain the purpose of the `<form>` element.

    - The `<form>` element is used to create an HTML form for collecting user input. It can contain various input elements such as text fields, checkboxes, radio buttons, and submit buttons.


17. What is the purpose of the `<head>` section in an HTML document?

    - The `<head>` section contains metadata about the document, including the title, character encoding, stylesheets, scripts, and other essential information for the browser.


18. What is the difference between `<ol>` and `<ul>`?

    - `<ol>` is used to create ordered lists, where each item is numbered, while `<ul>` is used to create unordered lists, where each item is preceded by a bullet point.


19. Explain the role of the `<table>` element in HTML.

    - The `<table>` element is used to create tabular data. It consists of rows (`<tr>`), columns (`<td>` or `<th>`), and headers (`<thead>`, `<tbody>`, `<tfoot>`).


20. What is the purpose of the `href` attribute in the `<a>` tag?

    - The `href` attribute specifies the URL of the destination page or resource that the link points to when clicked.