0% found this document useful (0 votes)
16 views11 pages

Computer Programming Basics Guide

The document provides an introduction to computers and programming, explaining key concepts such as what a computer is, the purpose of programming, and the differences between various computer architectures. It covers Python programming basics, including data types, functions, loops, and file handling, as well as advanced topics like arrays and strings. Additionally, it includes important distinctions and rules related to programming in Python.

Uploaded by

Divyansh Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views11 pages

Computer Programming Basics Guide

The document provides an introduction to computers and programming, explaining key concepts such as what a computer is, the purpose of programming, and the differences between various computer architectures. It covers Python programming basics, including data types, functions, loops, and file handling, as well as advanced topics like arrays and strings. Additionally, it includes important distinctions and rules related to programming in Python.

Uploaded by

Divyansh Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

INTRODUCTION TO COMPUTER & PROGRAMMING

1. What is a computer?
A computer is an electronic device that takes input, processes it, stores data, and produces
output.

2. What is a program?
A program is a set of instructions given to a computer to perform a specific task.

3. Why do we need programming?


Programming is needed to instruct the computer to solve problems and perform tasks.

4. Difference between calculator and computer?


A calculator performs fixed operations, while a computer can perform any task using programs.

5. What are the main components of a computer?


Input unit, Output unit, Memory, ALU, and Control Unit.

6. What is ALU?
ALU (Arithmetic Logic Unit) performs arithmetic and logical operations.

7. What is Control Unit?


It controls and coordinates all operations of the computer.

8. What is memory?
Memory stores data, instructions, and results.

9. What is Von Neumann architecture?


It is an architecture where program and data are stored in the same memory.

10. Difference between Von Neumann and Harvard architecture?


Von Neumann uses one memory for data and program, Harvard uses separate memory.

🔹 PYTHON INTRODUCTION
11. What is Python?
Python is a high-level, interpreted, open-source programming language.

12. Who developed Python?


Python was developed by Guido van Rossum.

13. Why is Python popular?


Because it is easy to learn, readable, and has large libraries.
14. Is Python interpreted or compiled?
Python is an interpreted language.

15. What is IDLE?


IDLE is Python’s Integrated Development and Learning Environment.

16. Difference between interactive mode and script mode?


Interactive mode executes one statement at a time; script mode runs a complete program.

🔹 TOKENS & KEYWORDS


17. What are tokens?
Tokens are the smallest units of a program.

18. Types of tokens in Python?


Identifiers, keywords, operators, literals, and delimiters.

19. What is an identifier?


A name used to identify variables, functions, or objects.

20. Rules for identifiers?


Must start with letter or underscore, no spaces, no special symbols, not a keyword.

21. What are keywords?


Keywords are reserved words with special meaning in Python.

22. Can keywords be used as variables?


No, keywords cannot be used as variable names.

🔹 DATA TYPES & VARIABLES


23. What is a data type?
A data type specifies the type of data a variable can store.

24. Is Python dynamically typed?


Yes, Python is dynamically typed.

25. Types of numbers in Python?


Integer, float, and complex.
26. What is a complex number?
A number with real and imaginary parts, written using j.

27. What is a variable?


A variable is a name that stores a value.

🔹 INPUT & OUTPUT


28. What does input() do?
It takes input from the user.

29. What type of input() returns?


It returns string by default.

30. What is print()?


print() displays output on the screen.

31. What is sep in print()?


It separates multiple values.

32. What is end in print()?


It specifies what to print at the end.

🔹 OPERATORS
33. What are operators?
Operators perform operations on operands.

34. Types of operators in Python?


Arithmetic, Relational, Logical, Assignment, Bitwise, Membership, Identity.

35. Difference between / and //?


/ gives float result, // gives integer result.

36. What is modulus operator?


% returns remainder.

37. What is ternary operator?


A single-line if-else statement.
🔹 DATA STRUCTURES
LIST

38. What is a list?


A list is an ordered, mutable collection of elements.

39. Can list store different data types?


Yes.

40. Is list mutable?


Yes, list is mutable.

TUPLE

41. What is a tuple?


Tuple is an ordered, immutable collection.

42. Difference between list and tuple?


List is mutable, tuple is immutable.

SET

43. What is a set?


Set is an unordered collection of unique elements.

44. Can set contain duplicates?


No.

45. Why list cannot be in set?


Because list is mutable.

DICTIONARY

46. What is dictionary?


A dictionary stores data in key-value pairs.

47. Are dictionary keys unique?


Yes.
🔹 DECISION MAKING
48. What is if statement?
It executes code when condition is true.

49. What is elif?


It checks multiple conditions.

50. What is indentation?


Spaces used to define code blocks.

🔹 LOOPS
51. What is loop?
Loop executes code repeatedly.

52. Types of loops?


for loop and while loop.

53. Difference between for and while?


for is used for sequences, while for conditions.

54. What is break?


Stops loop execution.

55. What is continue?


Skips current iteration.

🔹 FUNCTIONS
56. What is a function?
A function is a block of reusable code.

57. What is return statement?


It sends value back to caller.

58. Difference between return and print?


return gives value, print displays value.
*59. What is args?
Allows multiple positional arguments.

**60. What is kwargs?


Allows multiple keyword arguments.

61. What is lambda function?


An anonymous function.

🔹 RECURSION
62. What is recursion?
A function calling itself.

63. What is base condition?


Condition that stops recursion.

🔹 VERY IMPORTANT TRICK QUESTIONS ⭐


64. Is Python case-sensitive?
Yes.

65. Can variable change its type?


Yes.

66. Difference between = and ==?


= assigns value, == compares value.

67. Difference between is and = =?


is compares memory, == compares value.

68. Default return value of function?


None.
🔹 FILE HANDLING – VIVA QUESTIONS WITH ANSWERS

Basics

1. What is file handling?


File handling is the process of creating, reading, writing, and closing files.

2. Why do we need files?


Files are used to store data permanently.

3. What is a file?
A file is a collection of data stored on secondary storage.

4. Types of files in Python?


Text files and Binary files.

File Modes

5. What are file modes?


File modes specify how a file is opened.

6. Explain file modes.

 r → read
 w → write
 a → append
 r+ → read & write
 w+ → write & read
 a+ → append & read

7. What happens if file does not exist in r mode?


It gives an error.

8. What happens in w mode if file exists?


Old data is erased.

File Functions

9. What is open() function?


It opens a file.
10. Syntax of open()?
open("[Link]","mode")

11. What is close() function?


It closes the file.

12. Why should we close a file?


To free memory and save data properly.

13. What is read()?


Reads entire file content.

14. What is readline()?


Reads one line at a time.

15. What is readlines()?


Reads all lines as a list.

16. What is write()?


Writes data into file.

17. What is writelines()?


Writes multiple lines at once.

Advanced

18. What is with statement?


It automatically closes the file.

19. Advantage of with statement?


No need to close file manually.

20. Difference between text and binary file?


Text stores characters, binary stores bytes.

🔹 ARRAYS – VIVA QUESTIONS WITH ANSWERS


(In Python, arrays are usually implemented using lists or array module)

Basics
21. What is an array?
An array stores multiple values of same type.

22. Does Python support arrays?


Yes, using lists or array module.

23. Difference between array and list?


Array stores same type, list stores mixed types.

24. Which module is used for arrays?


array module.

Operations

25. How do you create an array?


Using array module or list.

26. What is indexing?


Accessing elements using position.

27. What is slicing?


Extracting part of an array.

28. Can array size change?


Yes, in lists.

29. Can arrays store different data types?


No, arrays store same type.

Tricky

30. Difference between list and array?


List is flexible, array is memory efficient.

31. What is NumPy?


A library for numerical arrays.

32. Why NumPy arrays are faster?


They use less memory and optimized operations.
🔹 STRINGS – VIVA QUESTIONS WITH ANSWERS

Basics

33. What is a string?


A string is a sequence of characters.

34. How strings are written in Python?


Using single, double, or triple quotes.

35. Are strings mutable?


No, strings are immutable.

String Operations

36. What is string indexing?


Accessing characters using index.

37. What is slicing in strings?


Extracting substring.

38. What is concatenation?


Joining strings using +.

39. What is repetition?


Repeating string using *.

String Functions

40. What is len()?


Returns length of string.

41. What is lower()?


Converts string to lowercase.

42. What is upper()?


Converts string to uppercase.

43. What is split()?


Splits string into list.
44. What is join()?
Joins list elements into string.

45. What is replace()?


Replaces substring.

Important Differences

46. Difference between find() and index()?


find() returns -1, index() gives error if not found.

47. Difference between strip(), lstrip(), rstrip()?


Removes spaces from both, left, and right.

48. What is string formatting?


Inserting values into string.

49. Methods of string formatting?


%, format(), f-string.

⭐ MOST IMPORTANT VIVA TRICKS


50. Why strings are immutable?
For memory efficiency and security.

51. Can string be changed?


No, only new string can be created.

52. Difference between file and variable?


Variable stores data temporarily, file permanently.

You might also like